Wednesday, May 05, 2004

This is a very usefull way to extract data from a DataTable. I never new it was possible until I found it on MSKB #308909
You can also copy DataRow objects from the results of a filtered DataView class or from the results of a Select method. For example: // Copy from the results of a Select method.
foreach (DataRow MyDataRow in DataTable1.Select("Region = 'WA'"))
{
DataTable2.ImportRow(MyDataRow);
}
Console.WriteLine(DataTable2.Rows.Count);
Console.ReadLine();

// Copy from the results of a DataView.
DataView1 = DataTable1.DefaultView;
DataView1.RowFilter = "Region = 'WA'";
for (int i = 0; i <= DataView1.Count - 1; ++i)
{
DataTable2.ImportRow(DataView1[I].Row);
}
Console.WriteLine(DataTable2.Rows.Count);
Console.ReadLine();

0 Comments:

Post a Comment

<< Home