Script(s)

what I learn is what u c

Posts Tagged ‘vb

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.Add(dsSource.Tables(0).Copy)

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)
 

Advertisements

Written by gchandra

November 15, 2007 at 2:12 pm

Posted in Asp.Net, Web Coding

Tagged with , , ,