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

What is wrong with the following code?

P: 2

Below is the code snippet where i would like to display a msgbox if there are no matching records. I always get a NullReferenceException at iRows = ds.Tables("dt").Rows.Count

Please help me solve it

Dim sql As String = "Select * from property where accountno = " & id.ToString '& "%'"
Dim sa As MySqlDataAdapter = New MySqlDataAdapter
sa.SelectCommand = New MySqlCommand(sql, conn)
Dim ds As New DataSet
Dim dt As DataTable = New DataTable("property")
Dim iRows As Integer = New Integer


iRows = ds.Tables("dt").Rows.Count
MsgBox(iRows, , "Number of datarows: iRows")
'test the value of iRow
If iRows > 0 Then
'No datarows present
'at least one datarow present
End If
Aug 12 '10 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 569
iRows = ds.Tables("dt").Rows.Count refers to a datatable you called "dt", but you only created a DataTable called "property".

Aug 12 '10 #2

P: 2
Thanks a lot :)
Aug 12 '10 #3

Post your reply

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