Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error Object reference not set to an instance of an object.

Status
Not open for further replies.

CookieNZ

MIS
Apr 22, 2002
48
NZ
The following prodedure should save a new row to the database.

I can't see what the error is, but when I create the command builder, the complier does not like dbsupport.

What have I done wrong

Dim NewRow As System.Data.DataRow
Dim dsadapter As OleDbDataAdapter
Dim dr As DataRow

dr = dssupport.Tables("Supportcall").NewRow()

dr("ID") = txtcallnumber.Text
dr("Customer") = cmbcustomer.Text
dr("Description") = txtcalldescription
dr("Contact") = txtcallcontact.Text

'Get connection string
strconn = "Provider=Microsoft.jet.oledb.4.0;" & "Data Source =P:\Support Calls\mosaic.mdb"

'Build SQL string
insertsql = "INSERT INTO Supportcall(ID, Customer, Description, Contact)" & " VALUES(?,?,?,?)"

'Create new data adpater
dbsupport = New OleDbDataAdapter(insertSQL, strconn)

'Create command builder for adapter
cmbbuild = New OleDbDataAdapter(dbsupport)

'Get Insert command object
dbsupport.InsertCommand = cmbbuild.GetInsertCommand()

'Submit insert statement through adpater
dbsupport.Update(dssupport, "Supportcall")

'Tell data set changes are complete
dssupport.AcceptChanges()
 
Looks like your case for insertSQL is not correct... that's probably your problem.

declared as insertsql

used as insertSQL

If that doesn't get it, then set a breakpoint in the code on that line, and when the debugger stops there, just mouse over all your vars and the one that reports its value as 'Nothing' is your culprit.

:)
paul
penny1.gif
penny1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top