PC Review


Reply
Thread Tools Rate Thread

copy datatables between datasets..

 
 
=?Utf-8?B?dmVua2F0?=
Guest
Posts: n/a
 
      25th Jan 2005
How do I copy a table from one dataset to another ?

code I am using and that is not working :
dataset2.tables.add(dataset1.tables(tablename))

Please help me.
prashant
 
Reply With Quote
 
 
 
 
Corbin
Guest
Posts: n/a
 
      25th Jan 2005
You have to use a separate instance of the table object. There is
probably a better way, but I copy tables as follows.

Dim dtNew As New DataTable
Dim rw As DataRow

dtNew = dtOld.Clone
For Each rw In dtOld.Rows
dtNew.Rows.Add(rw.ItemArray)
Next

 
Reply With Quote
 
=?Utf-8?B?SGF2YWdhbg==?=
Guest
Posts: n/a
 
      25th Jan 2005
> dataset2.tables.add(dataset1.tables(tablename))

Use the Dataset.Merge method
http://msdn.microsoft.com/library/de...mergetopic.asp

Ex:

dataset2.Merge(dataset1) 'merges entire dataset
dataset2.Merge(dataset1.Tables("tablename")) 'merges a specific table

Note:

If dataset2 is empty it will copy all tables from dataset1 into dataset2.
If dataset2 and dataset1 have tables with identical table names, this will
merge the data in dataset1 tables into dataset2 tables.
If dataset2 and dataset1 have tables with different table names, this will
copy the tables from dataset1 into dataset2.

Paul

 
Reply With Quote
 
=?Utf-8?B?VXJp?=
Guest
Posts: n/a
 
      25th Jan 2005
Hi all,
Actually it's a very good question.
If you don't affraid of performance issues, the best solution is to use the
merge operation.
ds1.Merge(ds2) or ds1.Merge(datatable1)
But if a given table doesn't exist in the destination's ds this code
actually will create a new instance of the datatable1 using DataTable.Copy()
operation and when will add it into your destination's ds.
One can think of another solution. Suppose I could detach the desired
DataTable from the source DS and attach it to the destination's DS. I will
save using this approach the DataTable.Copy() operation which is very
expensive and will merge my data properly,
Does anybody know how to accomplish that in .NET ?
Thanks,
Uri

"venkat" wrote:

> How do I copy a table from one dataset to another ?
>
> code I am using and that is not working :
> dataset2.tables.add(dataset1.tables(tablename))
>
> Please help me.
> prashant

 
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
Why WCF like DataSets, but not DataTables? Ronald S. Cook Microsoft VB .NET 0 19th Mar 2007 02:36 PM
Q: Datatables, Datasets and updating Geoff Microsoft C# .NET 4 30th Jan 2006 09:12 PM
RE: Adding DataTables from two different datasets =?Utf-8?B?UmF2aWNoYW5kcmFuIEouVi4=?= Microsoft ADO .NET 0 16th May 2005 12:22 PM
help with datasets, datatables, etc Dave Cullen Microsoft C# .NET 2 5th Apr 2004 03:24 PM
datasets and datatables William Ryan Microsoft Dot NET 0 29th Jun 2003 06:52 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:10 AM.