vb.net 2005 display sql results in datagrid

I want to display the results from a sql statement like this in a dategrid:

select this colume as 1st, sum((column2)+(column3)) as column2 from my table

My table has three columns, my datagrid needs just two because I want to display column2 and column3 totals as one column.  
LVL 2
bergertimeAsked:
Who is Participating?
 
ajitha75Connect With a Mentor Commented:
I think you are missing group by clause at the end of query
0
 
ajitha75Commented:


        Dim conn As New System.Data.SqlClient.SqlConnection("Server=abc;Database=Northwind;user=x;pwd=x")
        Dim sqlAdapt As New System.Data.SqlClient.SqlDataAdapter("select col1, SUM (col1 + col2 ) as col2 from table1", conn)
        Dim ds As New DataSet()

        conn.Open()
        sqlAdapt.Fill(ds)

        DataGridView1.DataSource = ds.Tables(0)
0
 
bergertimeAuthor Commented:
That's pretty much what I'm doing, it works until I add the SUM, then it just leaves it empty.  
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
ajitha75Commented:
I missed the group by clause.. the actual query was
select col1, SUM (col1 + col2 ) as col2 from table1 group by col1
can you paste your code here?
0
 
bergertimeAuthor Commented:
Dim cn As iDB2Connection = New iDB2Connection("User ID=XXXX;Password=XXX;Data Source=XX.XX.XX;Connection Timeout = 0")
        Dim cmd As iDB2Command
        Dim excelsqlstring As String

excelsqlstring = "SELECT IALRTAFC# AS AFC, IALRTORG AS Origin, IALRTDEST AS DEST, IALRTAWTLB AS Weight, IALRTDWTLB AS DimWeight , IALRTARTOT AS Billed, sUM(IALRTVPTOT-ialrtartot)  AS Cost" _
                & " FROM air400.IALERT WHERE ialrtcusbl = " & txtCustomerNumber.Text & " And ialrtstat <> ('A') and (substring(ialrtrevdt, 4, 2) || '0' || substring(ialrtrevdt, 1, 1) || substring(ialrtrevdt, 2, 2) >= " & lblStartDate.Text & ") AND (substring(ialrtrevdt, 4, 2) || '0' ||substring(ialrtrevdt, 1, 1) || substring(ialrtrevdt, 2, 2) <= " & lblEndDate.Text & ")"

Dim da As New iDB2DataAdapter(excelsqlstring, cn)
        Dim ds As New DataSet()

        'Open connection
        cn.Open()
        cmd = New iDB2Command(excelsqlstring, cn)
         da.Fill(ds)
         Grid1.DataSource = ds.Tables(0)
0
 
bergertimeAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.