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 February 14th, 2005, 01:40 PM
Registered User
 
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to unprsandeep Send a message via Yahoo to unprsandeep
Default Saving DataView as XML

Hi All.

I need to save data coming out database in XML format. However the number of files will depend on record count / maximum allowed in one file.

I know the way to restrict dataview to contain the records i want but not sure how i should save the data in XML format.

Any help will be appreciated.

Sandeep.

Sandeep Singh
 
Old February 15th, 2005, 12:22 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

DataSet is the only object that has the XML read/write capabilities. You could try maybe getting the enumerator and looping through that, creating the elements...

Brian
 
Old February 16th, 2005, 01:42 AM
Registered User
 
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ripplecreations
Default

DataSet is like an In Memory DataBase, the most beautiful feature of .net data library. DataSet uses XML to store the information in memory, so u need not bother creating XML, just call the appropriate method(datasetObject.WriteXml). And also u can Load the datafrom directly XML using Appropriate Load method(datasetObject.ReadXml)..

RippleCreations.com
 
Old February 16th, 2005, 03:36 AM
Registered User
 
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ripplecreations
Default

Code Sample from MSDN!
Might be helpful!!

[C#]
private void WriteXmlToFile(DataSet thisDataSet) {
    if (thisDataSet == null) { return; }
    // Create a file name to write to.
    string filename = "myXmlDoc.xml";
    // Create the FileStream to write with.
    System.IO.FileStream myFileStream = new System.IO.FileStream
       (filename, System.IO.FileMode.Create);
    // Create an XmlTextWriter with the fileStream.
    System.Xml.XmlTextWriter myXmlWriter =
       new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);
    // Write to the file with the WriteXml method.
    thisDataSet.WriteXml(myXmlWriter);
    myXmlWriter.Close();
 }



RippleCreations.com
 
Old February 17th, 2005, 01:44 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

However original poster wanted a XML file from DataView I think one possible way is changing your DataSet then using its WriteXml method as others mentioned,just use the same expression you used for DataView.RowFilter property,see the below code,
Code:
private void DataTableFilter(DataTable dt,string expression)
{
    DataColumn dc=new System.Data.DataColumn("temp");
    dc.DataType=System.Type.GetType("System.Boolean");
    dc.Expression=expression;

    dt.Columns.Add(dc);

    foreach(DataRow dr in dt.Rows)
    {
        if(!(bool)dr["temp"])
        {
            dr.Delete();
        }
    }
dt.Columns.Remove("temp");
dt.AcceptChanges();
}
now your datatable is another datatable! then you can call WriteXml method of its dataset,(when you call AcceptChanges you can't retrieve the previous state of your dataset anymore).

_____________
Mehdi.
software student.
 
Old February 18th, 2005, 03:40 AM
Registered User
 
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Here we go this code is working.
I think below code will help you to write xml file after filtering the records from dataview.

-----------------
SqlConnection SqlCn =new SqlConnection(ConnStr);
            SqlCn.Open();
            SqlDataAdapter sqlAdpt=new SqlDataAdapter(CommText,SqlCn);
            DataSet ds=new DataSet();
            sqlAdpt.Fill(ds);
            SqlCn.Close();
            DataView dv=new DataView(ds.Tables[0]);
            ds.Tables.Remove("Table");
            dv.Sort="EmployeeId";

            //Filter here if required
            dv.RowFilter="EmployeeID=1";

            dv.Table.TableName="TableFilterd";
            ds.Tables.Add(dv.Table);

            //Write XML into file.
            ds.WriteXml("C:\\temp\\test.xls");
;)

Neel
 
Old April 16th, 2007, 08:39 PM
Registered User
 
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In .NET 2.0, there is a DataView.ToTable().WriteXml(...) that would seem to do the trick.

Wally

 
Old April 19th, 2007, 03:12 PM
Registered User
 
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi I am also facing same problem but using visual studio developer edition 2.0...I created a dataset with a wizard and displaying the info based on last name parameter. I want to display the same information in xml format instaed of table. I know I can call getxml method but dont know where to put the code or do I have to create dataset again. Plz help me

Sadia Shoiab
 
Old May 21st, 2007, 03:15 PM
Registered User
 
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by wekelly
 In .NET 2.0, there is a DataView.ToTable().WriteXml(...) that would seem to do the trick.

Wally

Many thanks, Wally: that worked fine.

Aurelio.

 
Old May 26th, 2007, 02:12 AM
Registered User
 
Join Date: May 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to tanu80 Send a message via Yahoo to tanu80
Default

looking for brief description on ur problem

Hi This is tanaya looking for some guide in developing .net application





Similar Threads
Thread Thread Starter Forum Replies Last Post
Saving XML thru href link using XSLT kaukabhishek XSLT 16 June 25th, 2008 07:16 PM
saving xml in asp.net using schema kavifs ASP.NET 1.0 and 1.1 Professional 0 February 23rd, 2007 10:32 AM
Saving XML HELP!!! busher XML 2 November 23rd, 2004 12:34 PM
help with saving Collection to XML alevey VB.NET 2002/2003 Basics 2 December 22nd, 2003 08:34 PM
saving xml shine Classic ASP XML 1 July 22nd, 2003 08:12 AM





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