locked
Creating a UNION query in ASP.net RRS feed

  • Question

  • User129078304 posted

    I am trying to UNION the two queries below without success.

    Dim ds1 As New DataSet

    Dim MyConnection1 As New OleDb.OleDbConnection(GetPOWERConnectionString())

    Dim mydb1 As New OleDbDataAdapter("SELECT A.METRIC_ID, B.METRIC_DESC AS DESCRIPTION, SUM(A.METRIC_VALUE1) AS COUNT " & _

    " FROM PWR_METRIC_STORE A, PWR_METRIC_TYPE B" & _

    " WHERE A.METRIC_DATE >= ? AND A.METRIC_DATE <= ? " & _

    " AND A.METRIC_ID = B.METRIC_ID " & _

    " GROUP BY A.METRIC_ID, B.METRIC_DESC " , MyConnection1)

    " UNION " & _

    ("SELECT A.METRIC_ID, B.METRIC_DESC AS DESCRIPTION, SUM(A.METRIC_VALUE1) AS COUNT " & _

    "FROM PWR_METRIC_USER A, PWR_METRIC_TYPE B" & _

    "WHERE A.METRIC_DATE >= ? AND A.METRIC_DATE <= ? " & _

    "AND A.METRIC_ID = B.METRIC_ID " & _

    " GROUP BY A.METRIC_ID, B.METRIC_DESC ", MyConnection1)

     mydb1.SelectCommand.Parameters.Add(New System.Data.OleDb.OleDbParameter("@START_DATE", System.Data.OleDb.OleDbType.Date))

    mydb1.SelectCommand.Parameters("@START_DATE").Value = txt_Start_Date.Text

    mydb1.SelectCommand.Parameters.Add(New System.Data.OleDb.OleDbParameter("@END_DATE", System.Data.OleDb.OleDbType.Date))

    mydb1.SelectCommand.Parameters("@END_DATE").Value = txt_End_Date.Text

    mydb1.Fill(ds1)

    GridView1.DataSource = ds1

    GridView1.DataBind()

    MyConnection1.Close()

    Wednesday, June 8, 2011 12:51 PM

Answers

All replies