// MyDotNet\myCSharp\XML\ WriteXML.cs // Author: Mesbah U. Ahmed using System; using System.Data; // for ADO.Net using System.Data.SQL; // for SQL Server managed provider using System.IO; // for FileSteeam class using System.Text; // for StringBuilder class public class WriteXML { public static void Main() { // Build a connection SQLConnection myConn = new SQLConnection ("server=ahmed;uid=sa;pwd=nargis;database=Northwind"); // Build the SQL string StringBuilder mySql = new StringBuilder("SELECT ProductId, "); mySql.Append("ProductName, UnitPrice "); mySql.Append("FROM Products "); mySql.Append("WHERE UnitPrice < 10.00"); mySql.Append("ORDER BY UnitPrice "); Console.WriteLine(mySql); // Build the DataSet Command object SQLDataSetCommand myCmd = new SQLDataSetCommand (mySql.ToString(), myConn); // Build the DataSet DataSet myDs = new DataSet(); // Fill the DataSet with a dataset table named Products myCmd.FillDataSet(myDs, "Products"); // Get a FileStream object FileStream myFs = new FileStream ("myXmlData.xml",FileMode.OpenOrCreate,FileAccess.Write); // Apply the WriteXml method to write an XML document myDs.WriteXml(myFs); myFs.Close(); Console.WriteLine("File Written"); } }