Copy Datatable from one Dataset to another Dataset
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)
It helped me a lot………
thankyou chandra
Hari
February 14, 2008 at 8:57 am
Very useful for my problems, thanks chandra
Martyn
February 18, 2008 at 8:13 am
thank u very much………
vineeth
February 23, 2009 at 7:51 am
Thank u……………..
Tejas
October 3, 2009 at 7:16 am
NICE ANSWER THANQ VERY MUCHHH
D.RAJESH
February 16, 2010 at 3:32 am
Many Thanks krabbb
Jackyxman
July 20, 2010 at 9:09 am
it’s very useful for me. thank you very much
from gihan
gihan
November 23, 2010 at 11:47 pm
Great, I appreciate your collaboration!
Michael
December 21, 2010 at 4:26 pm
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?
Skronk
May 19, 2011 at 7:36 am
using copy is it any performance related issues are there?
Raghavendra
July 13, 2012 at 8:25 am