I have a program works fine in .NET 1.1 and just recompiled in .NET 2.0
without any code change. Compiles OK, but there is an exeception when
execute it.
Then I remove PK, it works all fine again.
Is this a known bug : PK on auto increase DataColumn in DataTable cause
NullReferenceException?
dcLineId = new DataColumn(LINEID_STR,
System.Type.GetType("System.Int32"));
dt.Columns.Add(dcLineId);
dcLineId.AutoIncrement = true;
dcLineId.AutoIncrementStep =1;
//if I remove this line, it works OK again on VS 2005
this.dt.PrimaryKey = new DataColumn[] {dcLineId};
.......
this.dt.Rows.Add(dr); //execute first time OK, second time throws
NullReferenceException
NullReferenceException
at System.Data.Index.CompareRecords(Int32 record1, Int32 record2)
at System.Data.Index.IndexTree.CompareNode(Int32 record1, Int32 record2)
at System.Data.RBTree`1.RBInsert(Int32 root_id, Int32 x_id, Int32
position)
at System.Data.Index.InsertRecord(Int32 record, Boolean fireEvent)
at System.Data.Index.ApplyChangeAction(Int32 record, Int32 action)
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.InsertRow(DataRow row, Int32 proposedID, Int32
pos, Boolean fireEvent)
at System.Data.DataRowCollection.Add(DataRow row)
...........
Thanks,
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
Ryan Liu
137 0173 5101
Shanghai Fengpu Software Co. Ltd
Shanghai , China
http://www.PowerCATI.com Powerful CATI!
http://www.fpsoft.net.cn
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.