// Arquivo de exemplo: WriteXml.cs
// Para compilar utilize: csc WriteXml.cs
using System;
using System.Data;
using System.Data.SqlClient;
using System.Security;
using System.Xml;
class Programa
{
	static void Main()
	{
		try
		{
			string getString=@"Data Source=.\SQLExpress;Integrated Security=SSPI;Initial Catalog=northwind;";			
			string sSql = "select CategoryID, CategoryName,	Description from Categories";
			using (SqlConnection conn = new SqlConnection(getString))
			{
				DataSet ds = new DataSet();
				SqlDataAdapter adapter = new SqlDataAdapter(sSql, conn);
				adapter.Fill(ds, "Categorias");
				ds.WriteXml(@"C:\Livro\Capitulo22\Ado.xml");
				Console.Write("Documento XML gravado com sucesso.");
				Console.Read();
			}
		}
		catch (SqlException ex)
		{
			Console.Write(ex.Message);
		}
		catch (SecurityException ex)
		{
      			Console.Write(ex.Message);
		}
		catch (Exception ex)
		{
			Console.Write(ex.Message);
		}
	}
}

