Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
lesson 13: dataAdapter.UpdateCommand = conn.CreateCommand()
I have been trying out the ADO.net lesson 13 (http://www.programmersheaven.com/2/Les_VBNET_13_p1
) on this site and have a problem I can't seem to overcome.
I adapted the solution to the "food for thought" exercise #5
. Here is the link for the source code:http://www.programmersheaven.com/articles/faraz/vbnet/lesson14/DBAppWithBothTables_Q5.zip
I adapted the solution from SQLServer to Access OLEDB. I am using my own DB instead of the programmersHeaven db (which I couldn't find on this site...), so i changed names of variables and tables, but I have basically kept the same structure intact.
The problem I am having is with InitializeCommands() which is meant to initialize the insert, update and delete SQL commands. When I run the program I get a NullReferenceException unhandled error. (Reference to object not established as an instance of an object). The line of code that throws the error is:
dataAdapterEvento.UpdateCommand = conn.CreateCommand()
(although I get the same error with DeleteCommand or InsertCommand too)
After I got the error I moved the call to InitializeCommands() to btnEditRecord_Click I am able to connect to the db, fill the dataset and navigate between records as I should be able to...so I would think that there is not a Null reference here...conn and dataAdapter are good because otherwise I wouldn't see any data. (both of them are btw are declared like this:
Public Class ADOForm
Private conn As OleDb.OleDbConnection
Private dataAdapterEvento As OleDb.OleDbDataAdapter
Any ideas out there as to why this doesn't work?
0 · ·