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.name, 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=192.168.23.12:C:\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")
DataGrid1.Refresh()
end sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim cb As OleDbCommandBuilder
DataGrid1.Update()
cb = New OleDbCommandBuilder(Me.myDA)
Me.myDA.SelectCommand.CommandText = strsqlc
cb.RefreshSchema()
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")
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?
Thanks
gajender