tags:

views:

11

answers:

1

I am reading my DataTable as follow:

foreach ( DataRow o_DataRow in vco_DataTable.Rows )
{
//Insert More Here
}

It crash; because I insert more records.

How can I read my DataTable without reading the new records? Can I read by RowState?

Thanks

A: 

Since I don't know what language you are using I can only give general advice.

In most (all?) languages it's not possible to do a foreach over a collection if you are modifying the collection. There are two common ways to deal with this.

Wild ass guessing pseudo code follows:

// first way uses array notation (if possible)
var no_of_rows = vco_DataTable.Rows.count();
for(var i = 0; i < no_of_rows; i++) {
  DataRow o_DataRow = vco_DataTable.Rows[i];
  //Insert More Here
}

// The second way copies the data
var my_copy = vco_DataTable.Copy()
foreach ( DataRow o_DataRow in my_copy.Rows )
{
   //Insert More into vco_DataTable Here
}
copy.Dispose() // delete/destroy the copy
Nifle
Nice! Thank You!
DataTable o_DataTable_ReadOnly = vco_DataTable.Copy();foreach ( DataRow o_DataRow in o_DataTable_ReadOnly.Rows ){ //Insert More into vco_DataTable Here}