One DS, two tables and two XML files?

A

al

Greetings,

I would like to know please how can I create two xml files from one
dataset with two tables in it? The WriteXML method of the DataSet
creates one XML file with BOTH tables of the dataset.


Dim ds as new dataset
Dim da as new dataadapter

'code goes here for declaration and database connection

da.fill(ds,"table1")
da.fill(ds,"table2")

ds.WriteXML(C:\text.xml) 'this will create ONE XML file...problem! I
need TWO

MTIA,
Grawsha
 
K

Kalpesh Shah

Check out if this helps

Since you have both the tables inside a single dataset & you want to create 2 seperate xml file (each for a table)

// this will write xml for table 1
DataTable dt2 = ds.Tables("Table2")
ds.Tables.Remove(dt2);

ds.Writexml("c:\table1.xml");

// after this is done, add table2 & remove table1
ds.Tables.Add(dt2);

DataTable dt1 = ds.Tables("Table1")
ds.Tables.Remove(dt1);

ds.Writexml("c:\table2.xml");

// after both the things are done, add back table1
ds.Tables.Add(dt1);

HTH :)
Kalpesh
 
A

al

Kalpesh Shah said:
Check out if this helps

Since you have both the tables inside a single dataset & you want to create 2 seperate xml file (each for a table)

// this will write xml for table 1
DataTable dt2 = ds.Tables("Table2")
ds.Tables.Remove(dt2);

ds.Writexml("c:\table1.xml");

// after this is done, add table2 & remove table1
ds.Tables.Add(dt2);

DataTable dt1 = ds.Tables("Table1")
ds.Tables.Remove(dt1);

ds.Writexml("c:\table2.xml");

// after both the things are done, add back table1
ds.Tables.Add(dt1);

HTH :)
Kalpesh

Kalpesh,

Thanks for your help. The problem I see with your solution is that
there is an open form bound to that dataset at the moment of XML
writing. That is, when I remove Table2 from dataset, the data bound to
the form will disappear too. I guess I will just create two datasets.

Grawsha
 
M

Miha Markic

Hi,

In that case you might want to copy dataset (see DataSet.Copy() method) and
manipulate on the copy.

--
Miha Markic - DXSquad/RightHand .NET consulting & software development
miha at rthand com

Developer Express newsgroups are for peer-to-peer support.
For direct support from Developer Express, write to (e-mail address removed)
Bug reports should be directed to: (e-mail address removed)
Due to newsgroup guidelines, DX-Squad will not answer anonymous postings.
 

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

Top