Search This Blog

2010/01/17

C# Implementation of Writing Data to XML Format using Dataset

C# Implementation of Writing Data to XML Format using Dataset’s :WriteXml method:

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Xml ;
namespace Writing_To_XML
{
class Program
{
static void Main(string[] args)
{
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Initial Catalog=sangram;Data Source=(Local)");
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from course", con);
SqlCommandBuilder sbuilder = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds, "course");
da = new SqlDataAdapter("select * from student", con);
da.Fill(ds,"student");

//setting relation between cno field common to both

DataRelation dataRel=ds.Relations.Add("RelName",ds.Tables[0].Columns["cno"],ds.Tables[1].Columns["cno"]);
dataRel.Nested=true ;
ds.WriteXml(@"I:\Trial\CourseStud.xml");
Console.WriteLine("Program Execution Finished:");
con.Close();
Console.ReadKey();
}
}

}



No comments:

Post a Comment