Error message with AutoNumber column issue- update DB

  • Thread starter Thread starter sea#
  • Start date Start date
S

sea#

I implemented article "Inserting relational data using DataSet and
DataAdapter" from this link:
http://www.codeproject.com/cs/database/relationaladonet.asp In my code.

It has a perfect explanation; still I got stuck at one point.
Debugger shows, that it happens when I'm at this stage:

static void CustDataAdapter_OnRowUpdate(object sender,
OleDbRowUpdatedEventArgs e) { OleDbCommand custCmd = new
OleDbCommand("SELECT @@IDENTITY", e.Command.Connection); //right
after this line e.Row["CustID"] =
custCmd.ExecuteScalar(); e.Row.AcceptChanges(); }

This method defines the OleDbRowUpdatedEventHandler event, which comes
to solve the AutoNumber column issue.

I got a message box error:

Problem populating dataset Box: [System.NullReferenceException: Object
reference not set to an instance of an object at (object sender,
OleDbRowUpdatedEventArgs e) in [path to file name]


There is some more text below it, but this seems to be the main thing.
Why do I get NullReferenceException? What did I missed?


sea#
 
sea#

Can you compile this assembly in debug mode and find the line where it
occurs? Or does it occur outside your code? If you get this in debug mode,
it should tell you the line where it occurs, which will help to narrow it
down.
 
Sorry for missing where you marked the line. It's hard to tell when
it's wrapped around in the reader.

If it happens on this line:

OleDbCommand custCmd = new OleDbCommand("SELECT @@IDENTITY",
e.Command.Connection);

Then it would indicate to me that either e is null (unlikely), or
Command is null, or Connection is null. What are these values when you
check them in the debugger (before this line is executed)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top