Table Mappings and Multiple Tables to XML

D

David W

Hi

I understand that a dataadaptor can have multiple tablemappings, but how can
I get the schemas and or xml data of multiple tables to be written to the
same file, in one action, but have it so each table is separated in its own
block?

The below code shows 2 tables, but the select statement only retreives all
rows from one of the tables. Need some way select all from both tables but
when written to xml, they are separate tables?

OdbcDataAdapter myAdapter = new OdbcDataAdapter();
myAdapter.TableMappings.Add("Address", "DataAddress");
myAdapter.TableMappings.Add("Products", "DataProducts");
//myConnection.Open();
OdbcCommand myCommand = new OdbcCommand("SELECT * FROM \"Address\"",
myConnection);
myCommand.CommandType = CommandType.Text;
myAdapter.SelectCommand = myCommand;
DataSet ds = new DataSet("AllData");
myAdapter.Fill(ds);
ds.WriteXml("d:\\AllData.XML", XmlWriteMode.WriteSchema);

Thanks in Advance

David
 
D

David W

Here is the solution to the problem. From the line myAdapter.Fill(ds);
replace with the below

myAdapter.Fill(ds,"Address");
OdbcCommand myCommand2 = new OdbcCommand("SELECT * FROM \"Products\"",
myConnection);
myCommand2.CommandType = CommandType.Text;
myAdapter.SelectCommand = myCommand2;
myAdapter.Fill(ds, "Products");
 

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