RE: Copy just some rows from a datatable to another datatable. by EltonW
EltonW
Mon Jan 02 16:07:03 CST 2006
If you use ADO.NET 2.0, you can use following method:
DataView dv = datatable.DefaultView;
dv.RowFilter = "FieldName='A'";
DataTable tableA = dv.ToTable();
dv.RowFilter = "FieldName='B'";
DataTable tableB = dv.ToTable();
But in ADO.NET 1.1, there isn't DataView.ToTable method. You need loop thru
dataview and 'copy' row to a datatable.
HTH
Elton Wang
"UJ" wrote:
> I have a datatable with a field in it that tells me where the data belongs
> (let's say the values are 'A' and 'B'). I want to split the table into two
> other tables where in one there are only the 'A' records and the other one
> has only the 'B' records.
>
> What's the easiest way to do it? I looked at a dataview but it has no copy,
> it has copyto.
>
> TIA - Jeff.
>
>
>