Table Mappings and Multiple Tables to XML

  • Thread starter Thread starter David W
  • Start date Start date
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
 
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");
 
Back
Top