Home Dashboard Directory Help

Funny one, DataTable internal index is corrupted by Mystery



Sign in
to vote
Type: Bug
ID: 98279
Opened: 9/20/2005 8:05:15 AM
Access Restriction: Public
User(s) can reproduce this bug


I got an error, quite a funny one.

Message: DataTable internal index is corrupted: '5'.

Source: System.Data/RBTree`1.RBInsert
StackTrace:    at System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32 position)
at System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32 position)
at System.Data.Index.RecordStateChanged(Int32 oldRecord, DataViewRowState oldOldState, DataViewRowState oldNewState, Int32 newRecord, DataViewRowState newOldState, DataViewRowState newNewState)
at System.Data.DataTable.RecordStateChanged(Int32 record1, DataViewRowState oldState1, DataViewRowState newState1, Int32 record2, DataViewRowState oldState2, DataViewRowState newState2)
at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Int32 position, Boolean fireEvent, Exception& deferredException)
at System.Data.DataTable.SetNewRecord(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean fireEvent)
at System.Data.DataRow.EndEdit()
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at AdonisTech.Adonis2006.HelperLibrary.TableHelper.SetRowValue(DataRow row, DataColumn column, Object value) in C:\ADONIS 2006\Application\HelperLibrary\TableHelper.vb:line 33
at AdonisTech.Adonis2006.WinUI.frmEditStayPackages.UpdatePackageData(tblStayPackagesRow row) in C:\ADONIS 2006\Application\WinUI\Stay\frmEditStayPackages.vb:line 127
at AdonisTech.Adonis2006.WinUI.frmEditStayPackages.UpdateData() in C:\ADONIS 2006\Application\WinUI\Stay\frmEditStayPackages.vb:line 115
at AdonisTech.Adonis2006.WinUI.frmEditStayPackages.SaveData() in C:\ADONIS 2006\Application\WinUI\Stay\frmEditStayPackages.vb:line 42
at AdonisTech.Adonis2006.WinUI.frmEditStayPackages.btnOK_Click(Object sender, EventArgs e) in C:\ADONIS 2006\Application\WinUI\Stay\frmEditStayPackages.vb:line 34
at System.Windows.Forms.Control.OnClick(EventArgs e)
Sign in to post a comment.
Posted by Hagelt18 on 8/5/2014 at 6:18 AM
It's the middle of 2014 now and this is still reproducible even with or without multithreading or the use of the ListChanged events. Just add this code to a form and call the Test() method.

public void Test()
            Random random = new Random();
            DataTable Table = new DataTable();
            Table.Columns.Add("Edited", typeof(CellObject));

            //Add Initial Rows
            for (int i = 0; i < 1000; i++)
                DataRow newRow = Table.NewRow();
                newRow["Edited"] = new CellObject(random.Next(0, 500), random.Next(0, 500));

            Table.DefaultView.Sort = "Edited";

            int EditNumber = 0;
            DateTime StartTime = DateTime.Now;
            while (DateTime.Now.Subtract(StartTime).TotalSeconds < 60)
                //Edit Columns
                foreach (DataRow dr in Table.Rows)
                    Console.WriteLine("Edit # " + EditNumber.ToString());
                    ((CellObject)dr["Edited"]).test1 = random.Next(0, 1000);
                    ((CellObject)dr["Edited"]).test2 = random.Next(0, 1000);
        public class CellObject
            public int test1;
            public int test2;

            public CellObject(int a, int b)
                test1 = a;
                test2 = b;

            public override string ToString()
                return test1.ToString();
Posted by Daniel Smith on 3/19/2010 at 4:34 AM
Is this being investigated? Seems like a lot of people are able to reproduce this. Any chance of some sort of official comment, or resolution?
Sign in to post a workaround.
Posted by Cam.H on 3/17/2008 at 7:19 AM
I had to do as per Hadi Eskandari's submission but for EVERY new row I added, not just on an empty datatable.
Posted by Farhad Jalali on 3/19/2007 at 9:18 AM

fixed my problem
Posted by repattern on 10/1/2006 at 8:32 PM
I got this exception thrown at me while trying to update a DataSet column bound to a ComboBox. I solved it by swapping all my ComboBoxes with Infragistics UltraComboBoxes.
Posted by Hadi Eskandari on 9/27/2006 at 12:19 AM
If you get this exception when trying to add a new record to an empty datatable, which has other views binded to data-aware controls, try adding and deleting a dummy row, before adding your main row like this:

MyDataSet.MyTableRow dummy = MyDataSet.MyTable.NewMyTableRow();

//Proceeed here
Posted by Mystery on 5/5/2006 at 9:56 AM
This error might appear in a web application when caching DataTable objects and creating DataViews on the DataTables, under stress.

A simple workaround is to use DataTable.Copy() to give every user a private copy in memory and create the DataView on the copy. Of course, performance will go down dramatically.

original code:

DataTable dt = (DataTable)Cache["key"];
if (dt != null)
        DataView dv = new DataView(dt);

new code:

DataTable dt = (DataTable)Cache["key"];
if (dt != null)
        DataTable dtCopy = dt.Copy();

        DataView dv = new DataView(dtCopy);
Posted by Mystery on 4/28/2006 at 1:49 AM
This problem has been encountered when multiple views of the same table have been created, each of which was linked to a data aware control. The workaround for this is to use the BeginInit and EndInit methods of each view.

// makes changes to table here
Posted by Mystery on 1/12/2006 at 7:25 AM
If the dataset happens to be on the client side and a lot of binding-sources are bound to it, merging and adding might produce the given exception. We were able to work around this by temporarily suspending the binding via BindingSource.SuspendBinding() during Merge.

// Controls are bound to BindingSource which is bound to the DataSet

DataSet.Merge( changes, false, MssingSchemaAction.Add ); // this formerly corrupted the dataset - exception was thrown on any subsequent NewRow()
BindingSource.ResetBinding( false )
Posted by Mystery on 10/13/2005 at 3:44 AM
Before adding the new row call BeginLoadData, after the row has been added call EndLoadData.

This works for adding new rows, not confirmed for updating existing rows.