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

February 14th, 2005, 01:40 PM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 15th, 2005, 12:22 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

February 16th, 2005, 01:42 AM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 16th, 2005, 03:36 AM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 17th, 2005, 01:44 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|
|

February 18th, 2005, 03:40 AM
|
|
Registered User
|
|
Join Date: Feb 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

April 16th, 2007, 08:39 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
In .NET 2.0, there is a DataView.ToTable().WriteXml(...) that would seem to do the trick.
Wally
|
|

April 19th, 2007, 03:12 PM
|
|
Registered User
|
|
Join Date: Apr 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 21st, 2007, 03:15 PM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

May 26th, 2007, 02:12 AM
|
|
Registered User
|
|
Join Date: May 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
looking for brief description on ur problem
Hi This is tanaya looking for some guide in developing .net application
|
|
 |