Re: on merging datasets and datatables

From: Kai Brinkmann [MSFT] (kaibrink_at_online.microsoft.com)
Date: 12/03/04


Date: Fri, 3 Dec 2004 10:39:22 -0800

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" <phil25840@yahoo.com> wrote in message 
news:uv$svVW2EHA.1076@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! 


Relevant Pages

  • Re: true-random number generator (TRNG) info.
    ... was putting forth a crackpot idea? ... I guess his reference to poker wasn't much ... Uhhhh....you didn't say anything at all about his creating an alias ... You have a warped understanding of the word "logic". ...
    (rec.gambling.poker)
  • Re: OSRegSetValueEx versus RegSetValueEx
    ... I went through code and almost each function has some Alias attached to it. ... >> I cannot find any reference to it on MSDN site, ... > It's an excellent registry class that I use whenever I need registry ...
    (microsoft.public.vb.general.discussion)
  • Re: Switch alias names....
    ... Filtered indexes? ... and then in the INIT event 'fool' all the controls on the form into ... Use table again in 0 alias foo order 1 ... It just means I can have a 'common' form2 that can reference either ...
    (microsoft.public.fox.programmer.exchange)
  • Switch alias names....
    ... Is there any way of being abe to switch the alias name that a table is ... Form1 then opens form2....I would like to reference one of the two tables on ... this send form as ALIAS3 ...
    (microsoft.public.fox.programmer.exchange)

Loading