I need to know how can I Stop foreach
at it's last iteration. I don't know why but it's iterating once more than needed.
following is the code.
var rslista = result.Tables[0];
foreach (DataRow row in rslista.Rows)
{
}
I need to know how can I Stop foreach
at it's last iteration. I don't know why but it's iterating once more than needed.
following is the code.
var rslista = result.Tables[0];
foreach (DataRow row in rslista.Rows)
{
}
Set a breakpoint inside your foreach loop and take a look at the actual row that is being looped over which you feel shouldn't be there.
Sometimes there is a setting where a newrow object is preset in the datatable. One possible way to skip such a row is to check the rowstate or check for a null value in a column you expect data to be in. You can use the continue command to skip the row.
Don't copy and paste of of this code, but rather analyze what your data is and determine if one of the concepts below can help you.
DataTable dt = new DataTable();
foreach (DataRow dr in dt.Rows)
{
if (dr.RowState == DataRowState.Added)
continue;
if (dr.RowState == DataRowState.Detached)
continue;
}