Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to remove unwanted DS fields before WriteToXML

Status
Not open for further replies.

majkinetor

Programmer
Feb 21, 2006
88
RS
This is the sample code I am using to create nes\ted xml.

Code:
	static void Main(string[] args)
		{
			
			string myConString = "Initial Catalog=Northwind;Data Source=10.32.34.180;Integrated Security=SSPI;";
			SqlConnection nwindConn = new SqlConnection(myConString);

			SqlDataAdapter custDA	= new SqlDataAdapter("SELECT CustomerID, CompanyName FROM Customers", nwindConn);
			SqlDataAdapter orderDA   = new SqlDataAdapter("SELECT OrderID, CustomerID, OrderDate FROM Orders", nwindConn);
			SqlDataAdapter detDA = new SqlDataAdapter("SELECT * FROM [Order Details]", nwindConn);

			nwindConn.Open();

			DataSet custDS = new DataSet("CustomerOrders");
			custDA.Fill(custDS, "Customers");
			orderDA.Fill(custDS, "Orders");
			detDA.Fill(custDS, "OrderDetails");
			
			nwindConn.Close();

			DataRelation rel = custDS.Relations.Add("CustOrders",
				custDS.Tables["Customers"].Columns["CustomerID"],
				custDS.Tables["Orders"].Columns["CustomerID"]);

			DataRelation rel2 = custDS.Relations.Add("Details",
				custDS.Tables["Orders"].Columns["OrderID"],
				custDS.Tables["OrderDetails"].Columns["OrderID"]);

			rel.Nested = rel2.Nested = true;
	
			custDS.WriteXml("c:\\_nested.xml");
		}
	}

I get this XML at output:

Code:
CustomerOrders>
  <Customers>
	<CustomerID>ALFKI</CustomerID>
	<CompanyName>Alfreds Futterkiste</CompanyName>
	<Orders>
	 [blue] <OrderID>10643</OrderID>[/blue]
	  <CustomerID>ALFKI</CustomerID>
	  <OrderDate>1997-08-25T00:00:00.0000000+02:00</OrderDate>
	  <OrderDetails>
		<OrderID>10643</OrderID>
		<ProductID>28</ProductID>
		<UnitPrice>45.6000</UnitPrice>
		<Quantity>15</Quantity>
		<Discount>0.25</Discount>
	  </OrderDetails>
	  <OrderDetails>
		<OrderID>10643</OrderID>
		<ProductID>39</ProductID>
		.......
		.......

I want to get it without line colored in blue.
How can I achieve that so that XMLExport "knows" that I don't want them. Can I somehow mark columns from dataset that I use for relation so that they don't appear double in XML Export.


Thx in advance


 
I was informed there is so called Transient Field in Java
Transient fields are not important for serialisation.

Maybe there is equivalent in dotNet if writetoxml was done using serialisation....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top