SIGN UP MEMBER LOGIN:    
ARTICLE

ADODataReader- Writing DataSets to XML

Posted by Hari Shankar Articles | ADO.NET in C# February 04, 2001
This file uses ADODataReader and other objects to write DataSets to XML and filling data from the XML files.
Reader Level:
Download Files:
 

This file uses ADODataReader and other objects to write DataSets to XML and filling data from the XML files.

using System;
using System.WinForms;
using System.Data;
using System.Data.ADO;
//Using System.IO;
public class DataAccess
{
private static string strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\Learning.net\\DataAccess\\Biblio.MDB"; 
public static void Main()
{
//string strCon="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Biblio.MDB";
//string strCon="\\";
ADOConnection mCon=new ADOConnection(strCon);
ADOCommand myCmd = new ADOCommand("Select * from authors", mCon);
ADODataReader myReader=null;
try
{
mCon.Open();
myCmd.Execute(out myReader);
if (myReader!=null)
while (myReader.Read())
Console.WriteLine("author name: {0}", myReader["author"]);
}
catch(Exception e)
{
//System.WinForms.MessageBox.Show(e.ToString());
MessageBox.Show(e.ToString());
//Console.WriteLine(e.ToString());
}
finally
{
if (mCon.State==DBObjectState.Open)
mCon.Close();
if(null!=myReader)
myReader=null;
}
DataAccess DA =new DataAccess();
DA.GetDataSet();
DA.ReadAndDisplayXml();
}
private void GetDataSet()
{
ADOConnection mCon=new ADOConnection(strCon);
DataSet myDS=new DataSet();
ADODataSetCommand myDSCommand=new ADODataSetCommand("Select * from Authors",mCon);
myDSCommand.FillDataSet(myDS,"Authors");
myDSCommand.FillDataSet(myDS,"Title Author");
myDS.WriteXml("myXmlDoc.xml");
foreach(DataRow myAuthor in myDS.Tables[0].Rows)
Console.WriteLine(myAuthor["Au_ID"].ToString());
myDS.Relations.Add("AuthorIsbn",myDS.Tables["Authors"].Columns["Au_ID"],myDS.Tables["Title Author"].Columns["Au_ID"]);
DataRow Au=myDS.Tables["Authors"].Rows[0];
DataRow[] isbn=Au.GetChildRows(myDS.Relations["AuthorIsbn"]);
Console.WriteLine("Total Child records for Authors Relationship = " +isbn.Length.ToString());
}
private void ReadAndDisplayXml()
{
System.IO.FileStream fsReadXml = new System.IO.FileStream("myxmldoc.xml",System.IO.FileMode.Open);
DataSet ds = new DataSet();
ds.ReadXml(fsReadXml);
foreach(DataTable myTable in ds.Tables)
Console.WriteLine(myTable.TableName);
}
}

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Nevron Gauge for SharePoint
Become a Sponsor