Copy Datatable from one Dataset to another Dataset

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

[sourcecode language=’vb’]
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)

2 thoughts on “Copy Datatable from one Dataset to another Dataset

  • February 14, 2008 at 8:57 am

    It helped me a lot………
    thankyou chandra


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: