NullReferenceException when you update a column value in OnRowUpdating event handler

J

Jiho Han

I am getting a NullReferenceException deep in the bowels of ADO.NET.

I figured out that it only happens when I change column values within RowUpdating
event handler.

private void _dataAdapter_RowUpdating(object sender, OleDbRowUpdatingEventArgs
e)
{
System.Diagnostics.Debug.WriteLine("QueryTable::OnRowUpdating");
if (e.Row.Table.Columns.Contains("MODIFYDATE"))
e.Row["MODIFYDATE"] = DateTime.Now;
if (e.Row.Table.Columns.Contains("MODIFYUSER"))
e.Row["MODIFYUSER"] = "ADMIN";
}

I am simply calling the dataadapter's Update method. I can only guess that
changing the column value in RowUpdating event is changing the internal state
that makes the whole thing fail.

Two questions:

1. Does anyone know what may be happening?

2. How do I troubleshoot this when an error is happening in the framework
like this? The disassembly view doesn't really help since I can't read IL.
I tried Reflector add-in which is good but it doesn't take me to the source
line where it's failing.

Thanks and I took out the above code and I am updating those fields before
I call Update method, following the wisdom gained from the following well-known
joke:

"Doctor, it hurts when I do this."
"Then, don't do it."

Jiho
 
J

Jiho Han

Ok, scratch that idea. I am still getting the same error. But I narrowed
it down to the DateTime field that's causing the problem.

For some reason, my update command will fail whenever I tried to update the
MODIFYDATE field (OleDbType.DBTimeStamp - sql datetime).
I am doing something like:

UPDATE HISTORY SET MODIFYDATE = ?, MODIFYUSER = ?, DESCRIPTION = ? WHERE
MODIFYDATE = ? AND MODIFYUSER = ? AND DESCRIPTION = ? AND HISTORYID = ?

for optimistic concurrency.
 

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

Top