What is wrong with the following code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kavya Rao
    New Member
    • Aug 2010
    • 2

    What is wrong with the following code?

    Hi,

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

    Please help me solve it
    Thanks

    Try
    Dim sql As String = "Select * from property where accountno = " & id.ToString '& "%'"
    Dim sa As MySqlDataAdapte r = New MySqlDataAdapte r
    sa.SelectComman d = New MySqlCommand(sq l, conn)
    Dim ds As New DataSet
    Dim dt As DataTable = New DataTable("prop erty")
    Dim iRows As Integer = New Integer


    Try

    dt.Columns.Add( "accountno" )
    ds.Tables.Add(d t)
    iRows = ds.Tables("dt") .Rows.Count
    MsgBox(iRows, , "Number of datarows: iRows")
    'test the value of iRow
    If iRows > 0 Then
    'No datarows present
    Else
    'at least one datarow present
    End If
  • MrMancunian
    Recognized Expert Contributor
    • Jul 2008
    • 569

    #2
    iRows = ds.Tables("dt") .Rows.Count refers to a datatable you called "dt", but you only created a DataTable called "property".

    Steven

    Comment

    • Kavya Rao
      New Member
      • Aug 2010
      • 2

      #3
      Thanks a lot :)

      Comment

      Working...