DataRow.Delete() throws System.ArgumentOutOfRangeException: Non-negative number required.

R

Ryan Liu

Hi,

When my code run to
DataRow.Delete()

It throws:

System.ArgumentOutOfRangeException: Non-negative number required.
Parameter name: length
at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array
destinationArray, Int32 destinationIndex, Int32 length)
at System.Data.Index.DeleteRecord(Int32 recordIndex)
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.SetNewRecord(DataRow row, Int32 proposedRecord,
DataRowAction action, Boolean isInMerge)
at System.Data.DataRow.Delete()




The datetable it belongs has a primary key:


DataColumn dcUserLoginName =new DataColumn(UserLoginName,
typeof(string));
dcUserLoginName.AllowDBNull = false;
this.currentQuotaUserDt.Columns.Add(dcUserLoginName);
this.currentQuotaUserDt.PrimaryKey = new DataColumn[] {dcUserLoginName};

Can someone tell me how could this happen and how to prevent it?


Thanks a lot!
Ryan
 
S

Shawn Wildermuth (C# MVP)

Hello Ryan,

You're not allowed to delete data in a DataSet...no...no...no....I am kidding...

Any chance that DataTable has a DataView associated with it somewhere? I
have seen this happen when an errant DataView was created and hasn't been
collected.


Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
http://adoguy.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top