473,549 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataRow.Delete( ) throws System.Argument OutOfRangeExcep tion: Non-negative number required.

Hi,

When my code run to
DataRow.Delete( )

It throws:

System.Argument OutOfRangeExcep tion: Non-negative number required.
Parameter name: length
at System.Array.Co py(Array sourceArray, Int32 sourceIndex, Array
destinationArra y, Int32 destinationInde x, Int32 length)
at System.Data.Ind ex.DeleteRecord (Int32 recordIndex)
at System.Data.Ind ex.ApplyChangeA ction(Int32 record, Int32 action)
at System.Data.Dat aTable.RecordSt ateChanged(Int3 2 record1,
DataViewRowStat e oldState1, DataViewRowStat e newState1, Int32 record2,
DataViewRowStat e oldState2, DataViewRowStat e newState2)
at System.Data.Dat aTable.SetNewRe cord(DataRow row, Int32 proposedRecord,
DataRowAction action, Boolean isInMerge)
at System.Data.Dat aRow.Delete()


The datetable it belongs has a primary key:
DataColumn dcUserLoginName =new DataColumn(User LoginName,
typeof(string)) ;
dcUserLoginName .AllowDBNull = false;
this.currentQuo taUserDt.Column s.Add(dcUserLog inName);
this.currentQuo taUserDt.Primar yKey = new DataColumn[] {dcUserLoginNam e};

Can someone tell me how could this happen and how to prevent it?
Thanks a lot!
Ryan
Jul 29 '06 #1
1 3221
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.Argument OutOfRangeExcep tion: Non-negative number required.
Parameter name: length
at System.Array.Co py(Array sourceArray, Int32 sourceIndex, Array
destinationArra y, Int32 destinationInde x, Int32 length)
at System.Data.Ind ex.DeleteRecord (Int32 recordIndex)
at System.Data.Ind ex.ApplyChangeA ction(Int32 record, Int32 action)
at System.Data.Dat aTable.RecordSt ateChanged(Int3 2 record1,
DataViewRowStat e oldState1, DataViewRowStat e newState1, Int32 record2,
DataViewRowStat e oldState2, DataViewRowStat e newState2)
at System.Data.Dat aTable.SetNewRe cord(DataRow row, Int32
proposedRecord,
DataRowAction action, Boolean isInMerge)
at System.Data.Dat aRow.Delete()
The datetable it belongs has a primary key:

DataColumn dcUserLoginName =new DataColumn(User LoginName,
typeof(string)) ;
dcUserLoginName .AllowDBNull = false;
this.currentQuo taUserDt.Column s.Add(dcUserLog inName);
this.currentQuo taUserDt.Primar yKey = new DataColumn[]
{dcUserLoginNam e};
Can someone tell me how could this happen and how to prevent it?

Thanks a lot!
Ryan

Jul 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2146
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows XP Pro SP 1, .Net Framework 1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I have simplified the code and data to isolate...
3
5026
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control, then put this control on a form. I use DataAdaptor to fill the data table and update database.
4
2880
by: Michael Carr | last post by:
I have a function that populates a class with values from a database. I'd like to pass into the function either a SqlDataReader or a DataRow, depending on which mechanism I'm using to retrieve data from the database. However, the two classes don't appear to have any common interfaces that would allow me to enumerate the fields. Yet, when you...
1
9959
by: Hozi | last post by:
I am getting the below error when asp.net tries to parse the .aspx file. The funny part is that the error only seems to be happening when viewing the page throuh IE 6 and not Netscape browsers. I am not sure exactly what is throwing it off, especially in the form tag Has anybody seen this happening to them? It worked on IE briefly and then...
5
5685
by: sdettmers | last post by:
Hi, Database: SQL Server Session: SQL Server Language: C# Application: ASP.Net I have created a login page which attempts to retrieve the users record from the database and I store the validated users DataRow into Session which is in SQLServer. I have listed the error below for you to
3
2831
by: DBC User | last post by:
I would like to delete a row from a dataset based on a condition. Here is what I am doing foreach(row in table1) { string key = row; foreach(row1 in table2) { if (row1.tostring().equals(key)) row1.delete();
1
2419
by: Ryan Liu | last post by:
Hi, Is that safe to say a Detached DataRow neve in a DataTable's Rows collectoin? But in my log file, I do see a Detached row: foreach(DataRow dr in this.currentQuotaUserDt.Rows) {
2
4823
by: =?Utf-8?B?TWFyYw==?= | last post by:
In Visual Studio 2005, I am developing a Windows Mobile application, using Mobile SQL 2005. I need Data from a Database to be shown in a DataGrid, this works. But now I want to be able to get the Data of the selected DataRow, for instance, I want to display the value of the "Klant" column of the selected Row using: DataRow currentRow =...
0
1176
by: =?Utf-8?B?SGFycnkgVg==?= | last post by:
I've begun to get exceptions when I try to write a DataRow, "Cannot implicitly cnvert striung to double..." In the past I didn't have this problem, but adding code to a solution that worked now throws exceptions: The string WATERCODE and DBDate SAMPDATE are fine, but the Double STALEN won't implicitly convert to a string as the value is...
1
2421
by: Andy B | last post by:
I have the following code: //delete the row in the table that has ID of 1. This line works fine. DataSet.Table.Rows.Find(1).Delete(); //Accept the delete changes to the table. This row returns 'object set to a null reference' exception. Why? DataSet.Tables.Rows.Find(1).AcceptChanges(); Why does this happen if the DataRow.Delete method...
0
7518
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7808
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.