P
Paul Guides
Hi all,
I am using the following code to remove rows from a table.
Only rows which match a certain value are removed.
The code works in one form very reliable and fails in another.
The only difference between the two usages seems to be, that
in the one Form a typed dataset is used and an untyped one
in the other.
DataTable tab = ds.Tables[ tabName ];
DataColumn col = tab.Columns[ colName ];
DataRowCollection rc = tab.Rows;
for( int idx = 0; idx < rc.Count; idx++ ) {
DataRow row = rc[ idx ];
if( row.RowState == DataRowState.Deleted ) {
if( row[ col, DataRowVersion.Original ].ToString()
== id ) {
rc.RemoveAt( idx );
idx--;
}
} else {
if( row[ col ].ToString() == id ) {
rc.RemoveAt( idx );
idx--;
}
}
}
The failure appears in the first RemoveAt statement:
The row is just not removed. No exception is thrown,
nothing happens, but the row just stays there. The
code, as shown above, then produces an endless loop.
As said above, in another Form this code works.
Karl
I am using the following code to remove rows from a table.
Only rows which match a certain value are removed.
The code works in one form very reliable and fails in another.
The only difference between the two usages seems to be, that
in the one Form a typed dataset is used and an untyped one
in the other.
DataTable tab = ds.Tables[ tabName ];
DataColumn col = tab.Columns[ colName ];
DataRowCollection rc = tab.Rows;
for( int idx = 0; idx < rc.Count; idx++ ) {
DataRow row = rc[ idx ];
if( row.RowState == DataRowState.Deleted ) {
if( row[ col, DataRowVersion.Original ].ToString()
== id ) {
rc.RemoveAt( idx );
idx--;
}
} else {
if( row[ col ].ToString() == id ) {
rc.RemoveAt( idx );
idx--;
}
}
}
The failure appears in the first RemoveAt statement:
The row is just not removed. No exception is thrown,
nothing happens, but the row just stays there. The
code, as shown above, then produces an endless loop.
As said above, in another Form this code works.
Karl