using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlXml;
using System.IO;
public class MainClass
{
public static void Main()
{
int result = 0;
string strConn = @"Provider=SQLOLEDB;server=.\sqlexpress;database=northwind;integrated security=SSPI";
string sql = "select employeeid,firstname,lastname from employees where employeeid=? for xml auto,root('MyRoot')";
SqlXmlCommand cmd = new SqlXmlCommand(strConn);
cmd.CommandText = sql;
SqlXmlParameter param = cmd.CreateParameter();
param.Value = "1";
StreamWriter writer = File.CreateText(Application.StartupPath + @"\sqlxmlresults.xml");
cmd.ExecuteToStream(writer.BaseStream);
writer.Close();
}
}
|