How do I copy datatable from one dataset to another.

  • Thread starter Thread starter Katit
  • Start date Start date
K

Katit

I get dataset from database. I need to take specific datatable out of
it and add it to second dataset to pass back from webservice.

ds.Tables.Add(dsPart.Tables[0]);

I get exception "Datatable already belongs to another dataset"
Which is true :) But why can't I do that?

TIA
 
Hello Katit,

use Clone() method like ds.Tables.Add(dsPart.Tables[0].Clone());

K> I get dataset from database. I need to take specific datatable out of
K> it and add it to second dataset to pass back from webservice.
K>
K> ds.Tables.Add(dsPart.Tables[0]);
K>
K> I get exception "Datatable already belongs to another dataset" Which
K> is true :) But why can't I do that?
K>
K> TIA
K>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hello Katit,

use Clone() method like ds.Tables.Add(dsPart.Tables[0].Clone());

K> I get dataset from database. I need to take specific datatable out of
K> it and add it to second dataset to pass back from webservice.
K>
K> ds.Tables.Add(dsPart.Tables[0]);
K>
K> I get exception "Datatable already belongs to another dataset" Which
K> is true :) But why can't I do that?
K>
K> TIA
K>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hello Katit,

yep, sorry, my error :)
it's Copy() definitely

K> Katit wrote:
K>
Michael said:
Hello Katit,

use Clone() method like ds.Tables.Add(dsPart.Tables[0].Clone());
Spasib!
K> Actually, it should be Copy(). Clone() only gets table with
K> structure, but no data.
K>
---
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top