Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 努力从数据库中获取XML以在表格或网格的表单上显示_C#_Asp.net_Sql Server_Linq - Fatal编程技术网

C# 努力从数据库中获取XML以在表格或网格的表单上显示

C# 努力从数据库中获取XML以在表格或网格的表单上显示,c#,asp.net,sql-server,linq,C#,Asp.net,Sql Server,Linq,我一直在尝试检索存储在sql server的XML字段中的XML数据,现在我需要在网页/表单中显示信息,以便向用户提供有关存储的报表XML数据的信息,以下是我的尝试,它引发了索引0异常 using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.We

我一直在尝试检索存储在sql server的XML字段中的XML数据,现在我需要在网页/表单中显示信息,以便向用户提供有关存储的报表XML数据的信息,以下是我的尝试,它引发了索引0异常

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
using System.Xml.Linq;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        XmlDocument xdoc = new XmlDocument();
        SqlConnection cnn = null;
        SqlCommand cmd = null;



        try
        {
            cnn = new SqlConnection();
            cnn.ConnectionString = "ICDBConnectionString";
            cnn.Open();

            string selectQry = "WITH XMLNamespaces('TUReport' AS Debtor) SELECT* FROM TUReport WHERE ConsumerID = @ID FOR XML RAW('TUReport');";
            cmd = new SqlCommand(selectQry, cnn);
            int ID = Convert.ToInt32(txtIDNumber.Text);
            cmd.Parameters.AddWithValue("@ID", ID);

            DataSet dataset = new DataSet();

            //System.IO.StringReader xmlSR = new System.IO.StringReader(cmd)

            XmlReader reader = cmd.ExecuteXmlReader();

            dataset.ReadXml(reader, XmlReadMode.ReadSchema);

            results.DataSource = reader;
            results.DataBind();
            cnn.Close();


            //if (reader.Read())

            //    xdoc.Load(reader);


        }

        catch (Exception ex)
        {
            throw ex;
        }

        finally
        {
            cmd.Dispose();
            cnn.Close();
        }

    }
}

SQL中的“选择”和之间缺少空格。Select FROM TUReport

catch语句仍然会抛出此错误。。App_Web_1nvanvoq.dll中出现“System.ArgumentException”类型的异常,但未在用户代码中处理其他信息:初始化字符串的格式不符合从索引0开始的规范。引发异常的是哪一行?TUReport中的ConsumerID是varchar吗?将字符串更改为int,但在调试程序时仍会出现相同的错误