By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,256 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

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

P: n/a
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(dcUserLoginNam e);
this.currentQuotaUserDt.PrimaryKey = new DataColumn[] {dcUserLoginName};

Can someone tell me how could this happen and how to prevent it?
Thanks a lot!
Ryan
Jul 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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
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(dcUserLoginNam e);
this.currentQuotaUserDt.PrimaryKey = new DataColumn[]
{dcUserLoginName};
Can someone tell me how could this happen and how to prevent it?

Thanks a lot!
Ryan

Jul 30 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.