Using SqlXmlParameter : SqlXmlCommand « ADO.Net « C# / CSharp Tutorial






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();
        }
    }








32.30.SqlXmlCommand
32.30.1.Save result from SqlXmlCommand to xml file
32.30.2.Using SqlXmlParameter
32.30.3.SqlXmlCommand and Xsl
32.30.4.Use StreamWriter to read result from SqlXmlCommand