468,773 Members | 2,454 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,773 developers. It's quick & easy.

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

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
1 3036
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.

Similar topics

4 posts views Thread by Michael Carr | last post: by
5 posts views Thread by sdettmers | last post: by
3 posts views Thread by DBC User | last post: by
2 posts views Thread by =?Utf-8?B?TWFyYw==?= | last post: by
reply views Thread by =?Utf-8?B?SGFycnkgVg==?= | last post: by
1 post views Thread by Andy B | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.