Script(s)

what I learn is what u c

Copy Datatable from one Dataset to another Dataset

with 4 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)
 

Written by gchandra

November 15, 2007 at 2:12 pm

Posted in Asp.Net, Web Coding

Tagged with , , ,

4 Responses

Subscribe to comments with RSS.

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

    Hari

    February 14, 2008 at 8:57 am

  2. Very useful for my problems, thanks chandra

    Martyn

    February 18, 2008 at 8:13 am

  3. thank u very much………

    vineeth

    February 23, 2009 at 7:51 am

  4. Thank u……………..

    Tejas

    October 3, 2009 at 7:16 am


Leave a Reply