可以的话.给我发一个简单的代码例子.不胜感激![email protected]

解决方案 »

  1.   

    using System;using Microsoft.Data.SqlXml;
    using System.IO;
    class Test
    {
          static string NorthwindConnString = "Provider=SQLOLEDB;Server=(local);database=Northwind;Integrated Security=SSPI";
          public static int testParams()
          {
             Stream strm;
             SqlXmlParameter p;
             SqlXmlCommand cmd = new SqlXmlCommand(NorthwindConnString);      
             cmd.CommandText = "SELECT FirstName, LastName, BirthDate FROM Employees WHERE LastName=? For XML Auto";
             p = cmd.CreateParameter();
             p.Value = "Fuller";
             string strResult;
             try 
             {
                strm = cmd.ExecuteStream();
                strm.Position = 0;
                using(StreamReader sr = new StreamReader(strm))
                {
                   Console.WriteLine(sr.ReadToEnd());
                }
             }
             catch (SqlXmlException e)
             {
                //in case of an error, this prints error returned.
                e.ErrorStream.Position=0;
                strResult=new StreamReader(e.ErrorStream).ReadToEnd();
                System.Console.WriteLine(strResult);
             }
             
             return 0;
       }
    public static int Main(String[] args)
    {
        testParams();
        return 0;
    }
    }