troubleshooting Question

Updating data with DataAdapter, Dataset and Grids

Avatar of rrmccall
rrmccall asked on
Visual Basic.NET
4 Comments1 Solution593 ViewsLast Modified:
Imports System.Data.OleDb
Public Class Form1
    Inherits System.Windows.Forms.Form
    Dim CN As New ADODB.Connection
    Dim  RsList As ADODB.Recordset
    Dim Cncmd As ADODB.Command

    Dim RS, RS1 As New ADODB.Recordset()
    Dim myDA As OleDbDataAdapter = New OleDbDataAdapter()
    Dim myDS As DataSet = New DataSet()
Dim strSQL as string = "SELECT cheminv.lot_number, chemical.chemical_id, chemical.current_cheminv_id,, chemical.generic_name WHERE cheminv.lot_number LIKE  'R%'"
Private Sub Form1_load (byval sender as . . .)
        CN = New ADODB.Connection     'ACCESS CONNECTION
        CN.Open("DRIVER={Firebird/Interbase(r)driver};Database=\Program                                                                                                                   Files\PKS\cmpdwin.dat;", "bob", "123")
        Cncmd = New ADODB.Command()
        Cncmd.ActiveConnection = CnnList
        Call Data() 'DISPLAY TABLE INFORMATION ON  Data Grid
end sub

Private sub data()
       ' diplay Table information on Data Grid
        RS = New ADODB.Recordset
        RS.Open(strsqlc, CN, 1, 2)

        '  Dim myDA As OleDbDataAdapter = New OleDbDataAdapter()
        '  Dim myDS As DataSet = New DataSet()
        myDA.Fill(myDS, RS, "cheminv")
        DataGrid1.DataSource = myDS.Tables("cheminv")

end sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim cb As OleDbCommandBuilder

        cb = New OleDbCommandBuilder(Me.myDA)
        Me.myDA.SelectCommand.CommandText = strsqlc
        Me.myDA.InsertCommand = cb.GetInsertCommand
        Me.myDA.UpdateCommand = cb.GetUpdateCommand
        Me.myDA.DeleteCommand = cb.GetDeleteCommand
        Me.myDA.Update(myDS.GetChanges, "cheminv") ,or
        Me.myDA.Update(myDS.Tables, "cheminv")
        Me.myDA.SelectCommand.CommandText = strsqlc
        cb.RefreshSchema() ' Use this every time the SelectCommand Command Text is altered
        myDA.update(myDS.tables("next table")
End Sub

When I select button2 to update the data i get an An unhandled exception of type 'System.NullReferenceException' occurred in chemicalgrid.exe: Additional information: Object reference not set to an instance of an object.  I do not understand the relationship between the grid and myda adapter and command builder.  Could somone explain to me?



Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros