check if the xml string is valid, the following works for meusing System;
using System.Data;
using System.Data.SqlClient;class TestXmlData
{
static void Main()
{
try
{
string xml = @"<root>
<sales ORDERID=""S002"" PRODUCTNAME=""Barbie Doll""
SHIP_ADD=""10 Newsland Estate""
PRICE_PER_QTY=""100""
QUANTITY=""10"">
</sales>
</root>"; SqlConnection cnShopper = new SqlConnection("server=localhost;Integrated Security=SSPI;Initial Catalog=tempdb");
SqlCommand cmdShopper = new SqlCommand();
cmdShopper.CommandType = CommandType.StoredProcedure;
cmdShopper.CommandText = "xml2db";
cmdShopper.Connection = cnShopper;
SqlParameter p = new SqlParameter("@xml",SqlDbType.VarChar);
p.Value = xml;
cmdShopper.Parameters.Add(p);
cnShopper.Open();
cmdShopper.ExecuteNonQuery();
cnShopper.Close();
}catch(Exception e)
{
Console.WriteLine("error:{0}",e.ToString());
} }
}also see
http://support.microsoft.com/default.aspx?scid=kb;EN-US;315968note, in ASP.NET, you may need to use SQL authentication instead of "Integrated Security=SSPI"
using System.Data;
using System.Data.SqlClient;class TestXmlData
{
static void Main()
{
try
{
string xml = @"<root>
<sales ORDERID=""S002"" PRODUCTNAME=""Barbie Doll""
SHIP_ADD=""10 Newsland Estate""
PRICE_PER_QTY=""100""
QUANTITY=""10"">
</sales>
</root>"; SqlConnection cnShopper = new SqlConnection("server=localhost;Integrated Security=SSPI;Initial Catalog=tempdb");
SqlCommand cmdShopper = new SqlCommand();
cmdShopper.CommandType = CommandType.StoredProcedure;
cmdShopper.CommandText = "xml2db";
cmdShopper.Connection = cnShopper;
SqlParameter p = new SqlParameter("@xml",SqlDbType.VarChar);
p.Value = xml;
cmdShopper.Parameters.Add(p);
cnShopper.Open();
cmdShopper.ExecuteNonQuery();
cnShopper.Close();
}catch(Exception e)
{
Console.WriteLine("error:{0}",e.ToString());
} }
}also see
http://support.microsoft.com/default.aspx?scid=kb;EN-US;315968note, in ASP.NET, you may need to use SQL authentication instead of "Integrated Security=SSPI"
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货