Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I have a large datatable which contain 10000 rows and 20 columns.
I have a method which will read the data from the first row. Once i read the data i need to remove the first row. so on the next call i will get the correct data.
When i try to call the method second time its give an error

Deleted row information cannot be accessed through the row

How can i solve this. please help

What I have tried:

C#
public static double[] ReadPresimulatedData()
        {
 double[] preValues = Array.ConvertAll<object, double>(dsPresimulated.Tables[0].Rows[0].ItemArray, o => (double)o);
dsPresimulated.Tables[0].Rows[0].Delete();
return preValues;
        }
Posted
Updated 16-Mar-16 6:50am
v2

You can't change any enumerable object your are currently looping through. You get errors like this and many more.

Why delete rows once you've parsed them? Why not just loop through then dispose of the whole table? It makes no sense with the explanation given. Do you mean that you are delete rows which meet a condition? Then you will have top remove them after you have finished your loop, or add the rows you want to keep to a new instance of a DataTable.

If this doesn't help then please describe in detail what you are trying to do and how you are looping through the rows. These points are relevant to any solution we can offer.

Thanks ^_^
Andy
 
Share this answer
 
Calling Delete sets the row's state to Deleted. It doesn't remove the row from the table. This is intended to be used when you want to make some changes to the data in-memory and then persist them to the database; the table needs to know which rows you've deleted in order to delete them from the database.

If you just want to remove the row, then use:
C#
dsPresimulated.Tables[0].Rows.RemoveAt(0);
 
Share this answer
 
Load the Data in a Queue then as you take each item off the queue and process it delete it from the database. You could also use a stack , depends if you want LIFO or FIFO.

Don't load it all into the queue and deleted from the data base before you process it; cos if your code crashes you will lose it all.

Another way is to "SELECT TOP 1 * FROM TABLE" and process the items one at a time then deleted it.

Balance between database calls and loading into memory, its this little design decisions that come back to haunt you later.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900