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.

Re: Copy just some rows from a datatable to another datatable. by W

W
Mon Jan 02 15:04:23 CST 2006

You can use DataTable.Select to get just the matching rows for both A and B.
That should do it for you.
"UJ" <fred@nowhere.com> wrote in message
news:ORgWf49DGHA.1384@TK2MSFTNGP11.phx.gbl...
>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.
>
>



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.
>
>
>

Re: Copy just some rows from a datatable to another datatable. by Cor

Cor
Tue Jan 03 03:41:21 CST 2006

UJ,

That ToTable as Bill mention is one of those things that are great in
version 2005 however almost nowhere written. If you have versions before
that, than you can maybe use this sample.

http://www.vb-tips.com/default.aspx?ID=dcad9a66-1366-4d61-8d32-1a580eb893b2

Remove in that than the selection to make it distinct

I hope this helps,

Cor