By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,035 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

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

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

Expand|Select|Wrap|Line Numbers
  1. Dim da As SqlDataAdapter
  2.         Try
  3.             ds = New DataSet
  4.             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)
  5.             ds.Clear()
  6.             da.Fill(ds, "ConnToSqlDrp")
  7.             If ds Is Nothing = True Then
  8.                 DGV2.Rows.Clear()
  9.                 Exit Sub
  10.             Else
  11.                 da.Fill(ds)
  12.                 DGV2.DataSource = ds.Tables(0)
  13.             End If
  14.         Catch ex As Exception
  15.             MsgBox(ex.Message.ToString())
  16.         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.
Sep 17 '13 #1
Share this Question
Share on Google+
1 Reply


zmbd
Expert Mod 5K+
P: 5,371
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.
Sep 17 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.