Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 5th, 2006, 07:14 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to remove unwanted DS fields before WriteToXML

This is the sample code I am using to create nested 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>
      <OrderID>10643</OrderID>
      <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
 
Old December 5th, 2006, 10:22 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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....

 
Old December 5th, 2006, 12:53 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Depending on your purpose, you could use the GetXml method instead of the WriteXml method to get the Xml, or write the xml out to a stream rather than a file, then massage the data (preferably using XSML to transform it rather than some brute force coding method) to remove the unwanted elements.

I do not know for certain, but I suspect there is no way to tell the dataset which elements to output or not output in the final xml - I have never seen such a thing, but I rarely use DataSets and more typically use the DataReader. DataSet functionality is too limiting and convoluted.

Woody Z
http://www.learntoprogramnow.com
 
Old December 6th, 2006, 06:44 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thx for you answer.

Its strange though....

One of the solutions is to run through the file at the end and remove unwated enteries using regular expressions...
For instance to remove all blue lines in the complete file but not those in OrderDetails, i can count number of spaces and tabs before along with the keywords....

 
Old December 8th, 2006, 01:52 AM
Friend of Wrox
 
Join Date: May 2005
Posts: 227
Thanks: 1
Thanked 7 Times in 7 Posts
Default

majkinetor:
My question to you is why the WHERE Clause is not used in the detDA table which will list only the order details equal to the Order ID of the Orders Table(OrderDA)? In fact, this should be an established relationship within the SQL database. From a Normalization and Performance POVs (Point-Of-Views),one should allow the SQL Server to do all the work. Then all ASP.NET would do would be to Read A Record(Row)-Write A Record(Row).





Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove the unwanted space at end of the string gmbalaa General .NET 2 August 21st, 2007 11:35 PM
Record Locking & Transactions in Strongly Typed DS Kia Visual Basic 2005 Basics 4 July 23rd, 2007 06:23 AM
Queue is not registered in the DS. nordestgaard All Other Wrox Books 2 June 30th, 2006 02:30 AM
.net: loading reports by passing DS is really slow joshsteiner Crystal Reports 1 September 13th, 2004 02:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.