System.NullReferenceException error!

ninjaimp

Well-known member
Joined
Jun 13, 2007
Messages
80
Programming Experience
1-3
Hi

I am very new to vb.net and still trying to get my head around it. I am trying to connect to an access db and then update a table with some test info

my code is:

VB.NET:
Dim con As New OleDb.OleDbConnection
        Dim sql As String
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter
        Dim MakeTableSQL As String
        Dim MySql As String
        Dim MySql2 As String
        Dim MySql3 As String

        con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\email.mdb"

        sql = "SELECT * FROM Email"
        da = New OleDb.OleDbDataAdapter(sql, con)

        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim dsNewRow As DataRow

        dsNewRow = ds.Tables("Labels").NewRow()

        dsNewRow.Item("Body") = "Test"

        ds.Tables("Labels").Rows.Add(dsNewRow)

        da.Update(ds, "Labels")

        MsgBox("New Record added to the Database")

eveytime i run the code i get the error 'System.NullReferenceException'

i wondered if anyone could help?
 
See my signature.. DW2 link. Section "Creating a Simple Data App".
Also read the DNU link
 
your problem seems simple, i guess you have only forgotten to create an instance of DataRow : drow = new datarow

unable to create an instance of an object will issue a nullreference exception

hope this would be helpful
 
your problem seems simple, i guess you have only forgotten to create an instance of DataRow : drow = new datarow

unable to create an instance of an object will issue a nullreference exception

hope this would be helpful

It's not that at all.

You're trying to access a table that doesn't exist.

The dataset contains no tables.

Tables("Label") will give you a nullreference exception.
 
Back
Top