Intermediate NullReferenceException when calling DataRow.EndEdit()

Hi there

I have got an application with the following cateristics:

* A datatable is populated with records from a database.
* A set intervals the database is checked for changed records,
and the corresponding DataRows in the DataTable is updated accordingly.
* Invoke is used at all times for the update to ensure that the update is done by the the thread that created the window handle.
* A DataView is connected to the DataTable.
* A GridControl (Xceed) is connected to the DataView (readonly)

The following is a snippet of the code used to update the DataRow:



private void updateRowFrom(DataRow row)
{
    try
    {
        DataRow mainRow = findRowFor(row);
        if (mainRow != null)
        {
            updateRow(mainRow, row);
        }
        else
        {
            DataTable dt = _gridView.Table;
            DataRow newRow = dt.NewRow();
            updateRow(newRow, row);
            dt.Rows.Add(newRow);
        }
    }
    catch(Exception ex)
    {
        log.Error(
"Error performing 'update row' operation.", ex);
    }
}

private void updateRow(DataRow row2update, DataRow newValues)
{
    row2update.BeginEdit();
    copyFields(newValues, row2update);
    row2update.EndEdit();
}

private void copyFields(DataRow fromRow, DataRow toRow)
{
    foreach (DataColumn col in fromRow.Table.Columns)
    {
        toRow[col.ColumnName] = fromRow[col.ColumnName];
    }
}


 



I have confirmed that the DataRows in copyFields contains the exact same columns.

Every once in a while (probably less then 1% of the time), the following exception is thrown when DataRow.EndEdit() is called:

2005-09-21 12:07:52,978 [ERROR] - Error performing 'update row' operation.
Exception: System.NullReferenceException

Source: System.Data
   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
eAirports.AODB.TrackingMerge.BO.TrackingGridManager.updateRowFrom(DataRow
row)


I have done a search on the web and it seems that some other developers have come up with the same error, but nobody published a solution.  The following two patches have also apparently been tried with no success:

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

If there are any fixes or workaround for this issue, or if somebody could point me in the right direction it would be greatly appreciated.

Regards,

Charl



Answer this question

Intermediate NullReferenceException when calling DataRow.EndEdit()

  • Gene R S

    Charl,

    Which version of .Net framework you are using We have similiar issue in .NET framework v1.1, and the issue has been fixed in .NET framework v2.0 since Beta1.

    Thanks,
    Kevin

  • slcy

    Kevin

    Thank you for your reply.  We are indeed using .NET framework v1.1.  Unfortionately upgrading to framework v2.0 is not an option at the moment.

    If anybody knows about a work-around for this for framework v1.1 your advice would be much appreciated.

    Charl

  • Intermediate NullReferenceException when calling DataRow.EndEdit()