最近做了一个WebService,在里面公开了一个方法ExcuteXmlReader,通过访问sql server中的NorthWind数据库中的product表建立一个XmlReader,使用的sql语句如下select * from product for xml auto,但是在asp.net下访问却生成不了xml数据,只能在windows form中生成完整的xml数据,请问哪位大哥有使用Sql Server的for xml语句的经历,是不是我的数据库哪里设置不对?
...全文
14520打赏收藏
求救,急
最近做了一个WebService,在里面公开了一个方法ExcuteXmlReader,通过访问sql server中的NorthWind数据库中的product表建立一个XmlReader,使用的sql语句如下select * from product for xml auto,但是在asp.net下访问却生成不了xml数据,只能在windows form中生成完整的xml数据,请问哪位大哥有使用Sql Server的for xml语句的经历,是不是我的数据库哪里设置不对?
public Service1()
{
..
connectionstring = (string)(ConfigurationSettings.AppSettings["connectionstring"]);
}
[WebMethods(true)]
public XmlDocument Products(string ProductId)
{
XmlDocument xml_dom = new XmlDocument();
string query_products = "select * from Products where productid='" + ProductId + "' for XML Auto";
using (SqlConnection con = new SqlConnection(connectionstring ))
using (SqlCommand cmd = new SqlCommand(products,con))
{
con.Open();
xml_dom.Load(cmd.ExcuteXmlReader());
return xml_dom;
}
}