How to get rows created using DataTable.NewRow () in C # / ADO.NET 2.0?
2 answers
I like TypeT's answer, but it might help to know that you always bind through the DataView to the DataTable and you can set it to filter on row state:
myDataSet.myTable.DefaultView.RowStateFilter = DataViewRowState.Added;
You can also create an additional DataView to view new or deleted rows, and then these views will not byte each other:
var addedView = new DataView(myDataSet.myTable);
addedView.RowStateFilter = DataViewRowState.Added;
+2
a source to share
I ran into this problem a while ago, however there is no good way to pull the added lines. I was just wasting my repos for you and found the implementation DataTable
I used:
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 still iterates, but it's nicely wrapped like IEnumerable
, and you don't have to write the code more than once.
+1
a source to share