473,498 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

on merging datasets and datatables

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
2 3186
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2673
by: William Ryan | last post by:
At the risk of sounding like a Big 5 consultant, "It depends". 1) Strongly typed datasets rock, they are faster than untyped, use intellisense... but your reason for wanting to use them is...
45
2381
by: cody | last post by:
I've seen an Introduction on ADO.NET with its Datasets on .NET TV and Iam now wondering how it is realized/used in real world applications. I don't believe that one would create a dataset and add...
2
2260
by: malcolm | last post by:
Hello, We have a robust (.NET 1.1 c# winforms) client-server application that utilizes many typed DataSets, typed DataTables and typed DataRows. Our application is a series of windows and popup...
3
11005
by: Mike | last post by:
Hi! I also asked this question in C# group with no results: I have 2 datasets loaded with data from two xml files having the same schema. The files contain data from yesterday and today. I'd...
2
1343
by: Dan Cooper | last post by:
I've got two datasets, each containing a single data table. dstDataSetA.Tables("TableA") dstDataSetB.Tables("TableB") I want to merge them together and delete any non-matching rows. ...
3
1574
by: cj | last post by:
I've used datatables and datasets before. Datasets being able to hold more than one table and datatables being only one table. My mind keeps coming up with recordsets. I can't remember how they...
7
1753
by: Jon Vaughan | last post by:
I have 2 datasets , one returned as a dataset from a webservice and one created client side form the same stored procedure that is returned from the webservice. I then try and merge the data, but...
0
1202
by: S.Tedeschi | last post by:
Hi all; as posted some days ago, I'm converting an on-line app; I used to heavily rely on strongly-typed DataSets directly dropped onto pages, and so viewed by code(-behind) as well. In the next...
12
3549
by: BillE | last post by:
I'm trying to decide if it is better to use typed datasets or business objects, so I would appreciate any thoughts from someone with more experience. When I use a business object to populate a...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7208
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4915
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3095
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1423
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.