locked
FAQ Item: What could cause the error “DataTable index is corrupted”?

    Question

  • What could cause the error “DataTable index is corrupted”?
    Sunday, June 20, 2010 3:14 PM

Answers

  • Here are 4 reasons how “DataTable internal index is corrupted” happens.

    1)      Changing values during DataView.ListChanged event. This is not supported.

    Look at the call stack and if you see DataView.OnListChanged and you are changing a DataRow/Set/Table, and then index corruption will likely happen (i.e. thrown from DataRow.EndEdit)

    Short description of the problem: the internal indexes getting notified of the edits out-of-order.

    Workaround - use the DataTable.RowChanged event instead of the DataView.ListChanged.

    2)      There is still an unfixed bug when merging data into an existing DataRow that starts in the Added or Deleted state and ends in the Modified row state.

    DataAdapter.Fill, DataSet.Load, DataTable.Load when LoadOption.PreserveChanges.

    DataSet.Merge, DataTable.Merge deleted rows.

    DataSet.Merge (DataRow[]) for added rows.

    Short description of the problem: The DataTable tells the DataView to “add” instead of “change”, resulting in index corruption.

    3)      Multi-threading

    The DataSet/DataTable and any connected objects are not thread safe.  Make sure you lock all the appropriate objects.

    4)      When the DataColumn.DataType is a reference type and the values are being changed instead of being treated as read only.

    Example: DataColumn.DataType is byte[] and the column sorted.  If the values in the byte array are changed instead of assigning a new byte array to the DataRow, the internal index doesn’t know about the change and becomes corrupt.  This is data being changed without the internal index being notified.

     

    Related threads:

    http://social.msdn.microsoft.com/Forums/en/adodotnetdataset/thread/6693db3a-1098-44d4-8b18-6ca85f59b075
    • Marked as answer by MSDN FAQ Sunday, June 20, 2010 3:15 PM
    Sunday, June 20, 2010 3:15 PM