Now I use Select and use a criteria which select only new rows. But is there any kind of GetInsertedRows-method. If I remember correctly there is status for each row so naturally one can loop through them all but that's not elegant.
-Cheers -Matti
Now I use Select and use a criteria which select only new rows. But is there any kind of GetInsertedRows-method. If I remember correctly there is status for each row so naturally one can loop through them all but that's not elegant.
-Cheers -Matti
I came across this issue myself a while ago, however there's no nice way of pulling out the added rows. I've just trawled my repositories for you and found the DataTable
implementation I used to use:
public class AdvancedDataTable : DataTable
{
public IEnumerable<DataRow> InsertedRowList
{
get
{
foreach (DataRow row in this.Rows)
{
if (row.RowState == System.Data.DataRowState.Added)
{
yield return row;
}
}
}
}
}
It's still doing an iteration, but it's nicely wrapped as an IEnumerable
and you won't have to write the code more than once.
I like TypeT's answer but it may help to know that you always bind through a DataView to a DataTable and you can set it to filter on the rows state:
myDataSet.myTable.DefaultView.RowStateFilter = DataViewRowState.Added;
You can also create an additional DataView to look at the new or deleted rows, and then those Views won't byte each other:
var addedView = new DataView(myDataSet.myTable);
addedView.RowStateFilter = DataViewRowState.Added;