what I learn is what u c

Copy Datatable from one Dataset to another Dataset

with 10 comments

 Copying a datatable from one dataset  to another was not that straightforward as I thought.

Dim dsSource As New DataSet
Dim dsDestination As New DataSet

'Your way to get data from XML or DB.
dsSource = object.getdata()

dsDestination = object.getmoredata()

'This is important, without this it will result in error
'when you try to copy the datatable from one dataset to another

dsSource.Tables(0).TableName = "NewTableName"


dsDestination.Tables(0).Tablename = "SomeTable"
dsDestination.Tables(1).Tablename = "NewTableName"   'The one we copied from other Dataset

Note 1 : When you are using more than one datatable in a dataset it is advisable you name the datatables.

Note 2 : These kinds of scenarios arise, when you are trying to establish Relation between datatables in a dataset.

(Cascading master – detail relation)

Written by gchandra

November 15, 2007 at 2:12 pm

Posted in Asp.Net, Web Coding

Tagged with , , ,

10 Responses

Subscribe to comments with RSS.

  1. It helped me a lot………
    thankyou chandra


    February 14, 2008 at 8:57 am

  2. Very useful for my problems, thanks chandra


    February 18, 2008 at 8:13 am

  3. thank u very much………


    February 23, 2009 at 7:51 am

  4. Thank u……………..


    October 3, 2009 at 7:16 am



    February 16, 2010 at 3:32 am

  6. Many Thanks krabbb


    July 20, 2010 at 9:09 am

  7. it’s very useful for me. thank you very much
    from gihan


    November 23, 2010 at 11:47 pm

  8. Great, I appreciate your collaboration!


    December 21, 2010 at 4:26 pm

  9. Thanks for the lesson! I have a question though. If dsSource and dsDestination are from different databases, like a live DB and a test one, will calling dsDestination.AcceptChanges() then add the new table to its database?


    May 19, 2011 at 7:36 am

  10. using copy is it any performance related issues are there?


    July 13, 2012 at 8:25 am

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: