Hi,
We have a process management system in VB .NET. It usually used text
files, but I'm trying to switch to using access database files and
ADO.
I made a form with a datagrid and a few buttons.
I define the variables for this program as follows:
Imports System.Data.Ole Db
Private dbConnRoutine As OleDbConnection = Nothing
Private dbAdapterRoutin e As OleDbDataAdapte r = Nothing
Private dbDataSetRoutin e As DataSet = Nothing
Private dbBuilderRoutin e As OleDbCommandBui lder = Nothing
When they press the LOAD button, the following is executed:
Dim connString As String
Dim sql As String
connString = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
Source=" + FileName
dbConnRoutine = New OleDbConnection (connString)
sql = "SELECT * FROM rtnmain"
Dim objCommand As New OleDbCommand(sq l, dbConnRoutine)
dbAdapterRoutin e = New OleDbDataAdapte r(objCommand)
dbAdapterRoutin e.TableMappings .Add("Table", "rtnmain")
dbBuilderRoutin e = New
OleDbCommandBui lder(dbAdapterR outine)
dbDataSetRoutin e = New DataSet("rtnmai n")
dbAdapterRoutin e.Fill(dbDataSe tRoutine, "rtnmain")
gridRoutine.Dat aSource =
dbDataSetRoutin e.Tables("rtnma in")
gridRoutine.Set DataBinding(dbD ataSetRoutine,
"rtnmain")
At which point, the data is loaded. No problems there.
Then, I'll add a row to the datagrid. I press the UPDATE button. The
following code is executed:
dbBuilderRoutin e.GetUpdateComm and()
dbAdapterRoutin e.Update(dbData SetRoutine)
The result is an error.
An unhandled exception of type 'System.NullRef erenceException '
occurred in system.data.dll
Additional information: Object reference not set to an instance
of an object.
Every example I've checked follows this process. Can anyone point out
what I'm doing wrong, or perhaps an alternative way of updating the
table?
Another question:: do I have to re-fill the dataset before trying to
update?
Thanks!
Tom Junior
We have a process management system in VB .NET. It usually used text
files, but I'm trying to switch to using access database files and
ADO.
I made a form with a datagrid and a few buttons.
I define the variables for this program as follows:
Imports System.Data.Ole Db
Private dbConnRoutine As OleDbConnection = Nothing
Private dbAdapterRoutin e As OleDbDataAdapte r = Nothing
Private dbDataSetRoutin e As DataSet = Nothing
Private dbBuilderRoutin e As OleDbCommandBui lder = Nothing
When they press the LOAD button, the following is executed:
Dim connString As String
Dim sql As String
connString = "Provider=Micro soft.Jet.OLEDB. 4.0; Data
Source=" + FileName
dbConnRoutine = New OleDbConnection (connString)
sql = "SELECT * FROM rtnmain"
Dim objCommand As New OleDbCommand(sq l, dbConnRoutine)
dbAdapterRoutin e = New OleDbDataAdapte r(objCommand)
dbAdapterRoutin e.TableMappings .Add("Table", "rtnmain")
dbBuilderRoutin e = New
OleDbCommandBui lder(dbAdapterR outine)
dbDataSetRoutin e = New DataSet("rtnmai n")
dbAdapterRoutin e.Fill(dbDataSe tRoutine, "rtnmain")
gridRoutine.Dat aSource =
dbDataSetRoutin e.Tables("rtnma in")
gridRoutine.Set DataBinding(dbD ataSetRoutine,
"rtnmain")
At which point, the data is loaded. No problems there.
Then, I'll add a row to the datagrid. I press the UPDATE button. The
following code is executed:
dbBuilderRoutin e.GetUpdateComm and()
dbAdapterRoutin e.Update(dbData SetRoutine)
The result is an error.
An unhandled exception of type 'System.NullRef erenceException '
occurred in system.data.dll
Additional information: Object reference not set to an instance
of an object.
Every example I've checked follows this process. Can anyone point out
what I'm doing wrong, or perhaps an alternative way of updating the
table?
Another question:: do I have to re-fill the dataset before trying to
update?
Thanks!
Tom Junior
Comment