Object reference not set to an instance of an object. System.NullR

G

Guest

Hi,
I have a very strange error.

string strFilter = "some filter expression";

drFoundRows = m_dsQuote.Tables["Some Table Name"].Select(strFilter);

if(1 != drFoundRows.Length)
{
return;
}

drFoundRows[0]["Some Column"] = 1;

I got the following error when I assign drFoundRows[0]["Some Column"] to 1.

Exception Type: System.NullReferenceException Exception Message: Object
reference not set to an instance of an object.
Exception Source: System.Data
Exception TargetSite: Void RecordStateChanged(Int32,
System.Data.DataViewRowState, System.Data.DataViewRowState, Int32,
System.Data.DataViewRowState, System.Data.DataViewRowState)

StackTrace Information
****************************************************
at System.Data.DataTable.RecordStateChanged(Int32 record1,
DataViewRowState oldState1, DataViewRowState newState1, Int32 record2,
DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord,
DataRowAction action, Boolean isInMerge)
at System.Data.DataRow.EndEdit()
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRow.set_Item(String columnName, Object value)
at RMQuotes.EditQuote.btAdd_Click(Object sender, EventArgs e)

I checked the drFoundRows[0]["Some Column"] have some integer value before I
made an assignment. This error never happened on some of my PCs (on my
development and one of the production server) and unpredictable happened on
others. My system is Windows 2003 server (without SP1), MDAC 2.8.

Thanks,
Dmitri
 
N

Norman Yuan

The only possible reason I can think of is that you supplied wrong column
name. Does nt column name has a space in it? Or you confused "-" with "_"?

If still not sure, I would add following debugging code to see the actaul
column name before drFoundRows[0]["ColumnName"]=1:

foreach (DataColumn col in m_dsQuote.Tables["TheTable"].Columns)
MessageBox.Show("***" + col.ColumnName + "***");
 
G

Guest

Column name is correct. Two independent people looked on it.
Yes, I tied this

foreach (DataColumn col in m_dsQuote.Tables["TheTable"].Columns)
MessageBox.Show("***" + col.ColumnName + "***");

And this

foreach (DataRow dr in m_dsQuote.Tables["TheTable"].Rows)
{
For(int i = 0; i < m_dsQuote.Tables["TheTable"].Columns.Count; i++)
{
MessageBox.Show("***" + dr[m_dsQuote.Tables["TheTable"].Columns.
ColumnName.ToString() + "***");
}
}

Correct values are here.

And by the way this application work great on some of the PC without any
modification. Just for test I performed fresh Windows 2003 server
installation and run it. Application worked excellent without any error. Now
I’ll try to install Windows 2003 updates to see what will brake.


Norman Yuan said:
The only possible reason I can think of is that you supplied wrong column
name. Does nt column name has a space in it? Or you confused "-" with "_"?

If still not sure, I would add following debugging code to see the actaul
column name before drFoundRows[0]["ColumnName"]=1:

foreach (DataColumn col in m_dsQuote.Tables["TheTable"].Columns)
MessageBox.Show("***" + col.ColumnName + "***");


Dmitri Kouminov said:
Hi,
I have a very strange error.

string strFilter = "some filter expression";

drFoundRows = m_dsQuote.Tables["Some Table Name"].Select(strFilter);

if(1 != drFoundRows.Length)
{
return;
}

drFoundRows[0]["Some Column"] = 1;

I got the following error when I assign drFoundRows[0]["Some Column"] to 1.

Exception Type: System.NullReferenceException Exception Message: Object
reference not set to an instance of an object.
Exception Source: System.Data
Exception TargetSite: Void RecordStateChanged(Int32,
System.Data.DataViewRowState, System.Data.DataViewRowState, Int32,
System.Data.DataViewRowState, System.Data.DataViewRowState)

StackTrace Information
****************************************************
at System.Data.DataTable.RecordStateChanged(Int32 record1,
DataViewRowState oldState1, DataViewRowState newState1, Int32 record2,
DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord,
DataRowAction action, Boolean isInMerge)
at System.Data.DataRow.EndEdit()
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRow.set_Item(String columnName, Object value)
at RMQuotes.EditQuote.btAdd_Click(Object sender, EventArgs e)

I checked the drFoundRows[0]["Some Column"] have some integer value before I
made an assignment. This error never happened on some of my PCs (on my
development and one of the production server) and unpredictable happened on
others. My system is Windows 2003 server (without SP1), MDAC 2.8.

Thanks,
Dmitri
 
K

Kevin Yu [MSFT]

Hi Dmitri,

You can try to add a breakpoint on this line: drFoundRows[0]["Some Column"]
= 1, and add drFoundRows[0]["Some Column"] to the watch window to see if we
can get the value of this column.

Also if the value cannot be get, please also add drFoundRows[0] to the
watch window and expand the watch by click the plus sign. Then you might
find the correct column in the member of drFoundRows[0].

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

The problem is that this error never happened in debugger. And this error
happened non on all of the PCs I tested. But I put message box to see the
value when exception was fired and value was correct.
 
G

Guest

I finally was able to reproduce this error. I installed Windows 2003 server
and all updates one by one. I tested my application after every new install.
Now I know who is the guilty. My application stopped working (started to
generate this error) after installation of Microsoft .NET Framework 1.1
Service Pack 1.
 
K

Kevin Yu [MSFT]

Hi,

Based on my research, this seems to be a known issue. Since accesssing the
data using column name fails, please try to get the value using the column
index. e.g. drFoundRows[0][0] (The second 0 is the index of the Some Column.

If there is a System.ArgumentOutOfRangeException thrown, please check the
following KB article.

http://support.microsoft.com/?id=836874

Also, are you binding a DataGrid to the data source? If so, please also
check the following KB, it might be helpful for you.

http://support.microsoft.com/?id=889531

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
K

Kevin Yu [MSFT]

Hi,

Did you check the KB article I provided in my last post? Also, could you
let me know if you're using a DataGrid to bind to the data source?

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
G

Guest

I was following the conversation you were having with Dmitri. I was able to
obtain the two hotfixes from your KB article that you posted before. I ran
into the exception listed below while testing. It occurs intermittently as
well. Any thoughts?

Unhandled Exception: System.IndexOutOfRangeException: Index was outside the
bounds of the array.
at System.Data.Common.StringStorage.Get(Int32 recordNo)
at System.Data.DataColumn.get_Item(Int32 record)
at System.Data.DataRow.get_Item(DataColumn column, DataRowVersion version)
at System.Data.DataRowView.GetColumnValue(DataColumn column)
at System.Data.DataColumnPropertyDescriptor.GetValue(Object component)
at
System.Windows.Forms.DataGridColumnStyle.GetColumnValueAtRow(CurrencyManager
source, Int32 rowNum)
at System.Windows.Forms.DataGridTextBoxColumn.Paint(Graphics g, Rectangle
bounds, CurrencyManager source, Int32 rowNum, Brush backBrush, Brush
foreBrush, Boolean alignToRight)
at
System.Windows.Forms.DataGridRelationshipRow.PaintCellContents(Graphics g,
Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush
foreBrush, Boolean alignToRight)
at System.Windows.Forms.DataGridRow.PaintData(Graphics g, Rectangle
bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean alignToRight)
at System.Windows.Forms.DataGridRelationshipRow.Paint(Graphics g,
Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn, Int32
numVisibleColumns, Boolean alignToRight)
at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&
boundingRect)
at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle
gridBounds)
at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
 
K

Kevin Yu [MSFT]

Hi,

It seems that this is not in the case of the KB articles. I think this
requires intensive troubleshooting. So I suggest you contact Microsoft PSS.
If this is really a product issue, they will try to give you a workaround
free of charge. You can get the contact information from the following link:

http://support.microsoft.com/common/international.aspx?rdpath=gp;en-us;offer
prophone

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
B

BertC

Dmitry,

Did you contact Microsoft Support? And if so, what was the response?
I'm running into a crash at the same location (i.e.
DataTable.SetNewRecord called by DataRow.EndEdit), although I think my
situation is a little different from yours. Did they provide you with
a hotfix or a workaround?

Bert
 

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