ExecuteScalar()没有返回单元格的全部内容
本文关键字:全部 单元格 返回 ExecuteScalar | 更新日期: 2023-09-27 18:19:23
我有一个返回XML字符串的存储过程。当我直接从表中复制这个时,我得到了和我期望的完全一样的结果。
然而,当我尝试用c#运行这个存储过程时,ExecuteScalar()只返回了我期望的70行中的46行。
下面是我使用的代码:using (SqlConnection con = new SqlConnection("Data Source=TEST;Initial Catalog=BMRSK;Integrated Security=True"))
{
using (SqlCommand buildXML = new SqlCommand("usp_BUILD_RISKCALC_XML", con))
{
buildXML.CommandType = CommandType.StoredProcedure;
con.Open();
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml((string)buildXML.ExecuteScalar());
xdoc.Save("Test.xml");
}
}
这是我从
行得到的异常xdoc.LoadXml((string)buildXML.ExecuteScalar());
未处理的System.Xml类型异常。XmlException'发生在System.Xml.dll
附加信息:发生了意外的文件结束。的下列元素不闭合:ARGUMENT, ARGUMENT- list, OPERATION,OPERATION-LIST RISKCALC。第一行,位置2034.
任何想法都将非常感激。谢谢你。
ExecuteScalar只读取2033个字符。使用ExecuteXmlReader代替。
private static void BuildXML()
{
using (SqlConnection con = new SqlConnection("Data Source=TEST;Initial Catalog=BMRSK;Integrated Security=True"))
{
using (SqlCommand buildXML = new SqlCommand("usp_BUILD_RISKCALC_XML", con))
{
buildXML.CommandType = CommandType.StoredProcedure;
con.Open();
XmlReader xmlReader = buildXML.ExecuteXmlReader();
XmlDocument xdoc = new XmlDocument();
xdoc.Load(xmlReader);
xdoc.Save("Test.xml");
}
}
}