By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,221 Members | 1,144 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,221 IT Pros & Developers. It's quick & easy.

on merging datasets and datatables

P: n/a
I am working in a web app that contains two datasets that are cached. I
would like to pull the first table from each dataset [0] and put each
into a single dataset, so as to have a single dataset with the
following:

DataSet ds=new DataSet();
DataTable dtroles=((DataSet)Cache["fullrolelist"].Tables[0]);
DataTable dtsub=((DataSet)Cache["subcommittees"].Tables[0]);
ds.Tables.Add(dtroles);
ds.Tables.Add(dtsub);

When I try this I get an error saying that these data tables already
belong to another dataset. Is there a way to extract a table from a
dataset and place it into another dataset? Am I approacing this the
right way? Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Your code doesn't work because you are simply creating another reference to
an existing DataTable object; you are not actually creating a new data
table. To do that, you need to use the Clone() method:

DataSet ds = new DataSet();
DataTable dtroles = ((DataSet)Cache["fullrolelist"]).Tables[0].Clone();
DataTable dtsub = ((DataSet)Cache["subcommittees"]).Tables[0].Clone();
ds.Tables.Add(dtroles);
ds.Tables.Add(dtsub);

Hope that helps.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Phil Townsend" <ph*******@yahoo.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
I am working in a web app that contains two datasets that are cached. I
would like to pull the first table from each dataset [0] and put each
into a single dataset, so as to have a single dataset with the
following:

DataSet ds=new DataSet();
DataTable dtroles=((DataSet)Cache["fullrolelist"].Tables[0]);
DataTable dtsub=((DataSet)Cache["subcommittees"].Tables[0]);
ds.Tables.Add(dtroles);
ds.Tables.Add(dtsub);

When I try this I get an error saying that these data tables already
belong to another dataset. Is there a way to extract a table from a
dataset and place it into another dataset? Am I approacing this the
right way? Thanks!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2

P: n/a

"Phil Townsend" <ph*******@yahoo.com> wrote in message
news:uv**************@TK2MSFTNGP09.phx.gbl...
I am working in a web app that contains two datasets that are cached. I
would like to pull the first table from each dataset [0] and put each
into a single dataset, so as to have a single dataset with the
following:

DataSet ds=new DataSet();
DataTable dtroles=((DataSet)Cache["fullrolelist"].Tables[0]);
DataTable dtsub=((DataSet)Cache["subcommittees"].Tables[0]);

Re: on MERGing ...

ds.Merge(dtroles)
ds.Merge(dtsub)

David
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.