none
DataTable internal index is corrupted ... Is exist an reason? RRS feed

  • Question

  • Hello people, how are you?

    I'm in front of a strange error.

    I have a data form, that show and manage the data by a BindingSource control.

    I hava a dataGridView and individuals controls like textbox to edit them.

    It's work fine at the begin , but after some adds, removes or updates, the .Net retrives me the follow exception:

    "DataTable internal index is corrupted: '5'"


    It's very borried.... it's an ilogical error....

    Does anybody have some tip?

    Thank you.

    André B.

    Monday, January 9, 2006 8:53 PM

Answers

  • Here are 4 reasons that I know how DataTable internal index is corrupted: '5' happens.

      

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

    Look at the callstack and if you see DataView.OnListChanged and you are changing a DataRow/Set/Table, 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.

     

    Saturday, November 1, 2008 1:16 AM
    Moderator

All replies

  • Did you ever find a solution to this problem?  I am having a similar exception and have been stumped....  The exception is being thrown while trying to use the FindBy.... (primary key) method in a typed dataset. Any suggestions are appreciated! Thanks!

    Here is the exception:

    System.InvalidOperationException: DataTable internal index is corrupted: '13'.
       at System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex)
       at System.Data.DataTable.FindRow(DataKey key, Object[] values)
       at System.Data.DataTable.FindByPrimaryKey(Object[] values)
       at System.Data.DataRowCollection.Find(Object[] keys)
       at ESC.SV.Business.Trending.TrendingServiceDataSet.RefreshInfoDataTable.FindByNaturalKey(String NaturalKey)
       at ESC.SV.Business.Trending.TrendingDataService.GetOrCreateRefreshInfoRow(String naturalKey)
       at ESC.SV.Business.Trending.TrendingDataService.RefreshAverageData(ParameterIntervalCollection parameters)

    Friday, January 20, 2006 9:10 PM
  • I'm also having the same problem when adding rows to a bound DataTable. I'm stumped as well.
    Thursday, February 2, 2006 7:37 AM
  • Not quite sure about the problem but you can try COMMIT the underlying DataTable before doing a Find.

    Hope this helps!!

    -Jay


    ** Mark the best replies as answers!

    Thursday, February 2, 2006 7:56 PM
  • I actually tracked my problem down to an EndEdit on the datarow. I'm not actually adding the row at all, I'm just setting some field values. I put a try/catch around the call to EndEdit and am eating the exception and it seems to still commit the values. Though I'm afraid that something wacky is just waiting to happen. I have a feeling it's related to databinding somehow. Hmmm.....

    Thursday, February 2, 2006 9:24 PM
  • Beth,

     

    Did you ever resolve this problem.  My code throws this error when I call the EndEdit method. Should I also just "eat the exception?"

     

    Monday, October 27, 2008 7:56 PM
  • Here are 4 reasons that I know how DataTable internal index is corrupted: '5' happens.

      

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

    Look at the callstack and if you see DataView.OnListChanged and you are changing a DataRow/Set/Table, 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.

     

    Saturday, November 1, 2008 1:16 AM
    Moderator
  • I know, ist a very old Thread:

    But with this Tip you can find out what could be the Problem.

    Attach to the Event RowChanging from the DataTable.

    So you get every Row that would be changed. so you have the Chance to find out which 'Update' of the Row causes the Intern dataTable Index error.

    I had the Problem that i loaded a Datatable and then i wsnt able to Add new Rows because of the index error.

    Which the above Event i find out, that i do an update on the Row which causes this error

    Thursday, September 3, 2015 8:34 AM