0

ds1 variables contain data but an error NullReference Exception occured at this point

`TextBox2.Text = ds1.Tables("Custmor").Rows(0).Item(0).ToString()`

Actual code block is :

Try
  con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Pradnya_DataB.mdb"
  con.Open()

  ds1 = New DataSet
  ss = "Select c1.cust_name,c1.cust_bottle_type,c2.B_Pending From Customer c1"
  ss = ss + " INNER JOIN Bottel_Collect c2 ON c2.Cust_ID=c1.Cust_ID WHERE c1.Cust_ID=" & CInt(lblText.Text)
  'ss = "Select * from Customer"

  da = New OleDbDataAdapter(ss, con)
  da.Fill(ds1)
  If ds1.Tables.Count > 0 Then
    TextBox2.Text = ds1.Tables("Custmor").Rows(0).Item(0).ToString()
    TextBox5.Text = ds1.Tables("Customer").Rows(0).Item(1).ToString()
    TextBox6.Text = ds1.Tables("Bottel_Collect").Rows(0).Item(5).ToString()
  End If
  con.Close()
  rd.Close()
Catch ex As Exception
  MsgBox(ex.Message)
End Try
Uours
  • 2,517
  • 1
  • 16
  • 21
  • Nearly all NullReference Exceptions have the same set of causes. See [NullReference Exception in Visual Basic](http://stackoverflow.com/a/26761773/1070452) for help on this. The DataAdapter will create tables, but it does not name them, one `da.Fill` statement wont create 3 tables. See "Data Provider Objects" in the link. – Ňɏssa Pøngjǣrdenlarp May 27 '15 at 11:34
  • And even you had more than one table, and even if they were named, `"Custmor"` would be a misspelling. Do look at ds1.Tables.Count in your immediate window right after the da.Fill command and explore from there. – clweeks May 27 '15 at 12:11

0 Answers0