PC Review


Reply
Thread Tools Rate Thread

Copy just some rows from a datatable to another datatable.

 
 
UJ
Guest
Posts: n/a
 
      2nd Jan 2006
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.


 
Reply With Quote
 
 
 
 
W.G. Ryan - MVP
Guest
Posts: n/a
 
      2nd Jan 2006
You can use DataTable.Select to get just the matching rows for both A and B.
That should do it for you.
"UJ" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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.
>
>



 
Reply With Quote
 
=?Utf-8?B?RWx0b24gVw==?=
Guest
Posts: n/a
 
      2nd Jan 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.
>
>
>

 
Reply With Quote
 
Cor Ligthert [MVP]
Guest
Posts: n/a
 
      3rd Jan 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?...2-1a580eb893b2

Remove in that than the selection to make it distinct

I hope this helps,

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataTable.Select vs DataTable.rows.Find vs foreach Dave Microsoft C# .NET 1 17th May 2007 09:06 PM
Updating datatable using datatable.rows.find() Lars E Microsoft C# .NET 1 27th Apr 2006 09:28 AM
DataTable.Select() - is it possible to pass rows back to datatable =?Utf-8?B?QW5kcmUgUmFuaWVyaQ==?= Microsoft ADO .NET 5 9th Nov 2005 05:10 PM
Clone DataTable or Copy DataTable Problem Kelvin Microsoft C# .NET 0 13th Dec 2004 07:55 AM
How can I use real SQL on a DataTable? i.e. not array of rows using a filter... as in DataTable.Select Dan V. Microsoft C# .NET 3 1st Jul 2004 03:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:23 AM.