query returns Dataset table rows count 1 with no data in the table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sahu1988
    New Member
    • Sep 2013
    • 1

    query returns Dataset table rows count 1 with no data in the table

    I am loading a datagriview with data in the tables.
    Below is the code I used.

    Code:
    Dim da As SqlDataAdapter
            Try
                ds = New DataSet
                da = New SqlDataAdapter("select A.ANALCODE 'ANALYSIS CODE ID',B.ANALCODEDESC 'ANALYSIS CODE DESC' from ACT00052_P A,ACT00051_P B where B.ANALCODE = A.ANALCODE and A.SACCTCOMB = '" & cmbAccount.Text & "' order by A.ANALCODE", sqlCon1)
                ds.Clear()
                da.Fill(ds, "ConnToSqlDrp")
                If ds Is Nothing = True Then
                    DGV2.Rows.Clear()
                    Exit Sub
                Else
                    da.Fill(ds)
                    DGV2.DataSource = ds.Tables(0)
                End If
            Catch ex As Exception
                MsgBox(ex.Message.ToString())
            End Try
    There is no data in the table but ds is Nothing is going False and the control is moved to else part of the program.
    I am using VS 2012.Please help me.
    Last edited by zmbd; Sep 17 '13, 01:38 PM. Reason: [Z{Please use the [CODE/] button to format posted code/html/sql - Please read the FAQ}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    ds Is Nothing
    You've set da = New SqlDataAdapter( "select A.ANALCODE 'ANALYSIS CODE ID'(...)
    (I am guessing the "DA" should be "DS" - yes?)
    So ofcourse your code is branching to the false statement as written because ds Is Nothing is checking the object "DS" and not the values contained therein (even if you have the "DA"/"DS" thing correct, then "DS" was set to a new object in line 3).

    You need to be checking for the records in the data source/table.

    Someone a little more versed than I in dot-net is going to have to help you with that method.
    Last edited by zmbd; Sep 17 '13, 01:49 PM.

    Comment

    Working...