problem using Dataset.WriteXml()
I have a problem getting Dataset.WriteXml() to create a nested xml
realtionship. All I get is an inline xsd (all nodes are children of
the root). Documentation says to use Dataset.Relations.Nested="true";
but this doesn't produce the nested xml as it should. I have even
used a unit test, "MessageBox.Show(Dataset.Relations.Nested.ToString ());".
I get the "True" as an answer. So, the ReationsCollection has a
relation and it is nested. Why then doesn't it work according to the
documentation. I have created this example using the Visual Designer
and coded it programmatically and both have the same results.
Below is the code that I am using...
cmd=new SqlCommand();
cmd.Connection=conn;
//cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="select * from customers";
//cmd.Parameters.Add("@PNR_no", SqlDbType.VarChar);
//cmd.Parameters["@PNR_no"].Value="DA00130247";
da = new SqlDataAdapter(cmd);
ds = new DataSet();
ds.ReadXmlSchema(@"c:\Inetpub\wwwroot\proXMLApp\XM LFile1.xsd");
string str=@"c:\test.xml";
da.Fill(ds,"Customers");
cmd.CommandText="select * from orders";
da1 = new SqlDataAdapter(cmd);
da1.Fill( ds,"Orders");
//DataRelation drCust = ds.Relations.Add("Customers_Orders",ds.Tables["Customers"].Columns["Customer_Id"],ds.Tables["Orders"].Columns["Customer_Id"]);
//drCust.Nested=true;
ds.WriteXml(str)
The tables used i.e Customers and Orders have a linking field Customer_Id where Customers is the master table. I am using the xml schema(XMLFile1.xsd) file to achieve the same.
Thanks
|