【问题标题】:Reading XML Data using SqlDataReader使用 SqlDataReader 读取 XML 数据
【发布时间】:2017-03-22 15:00:36
【问题描述】:

我有一个创建 XML 文档的存储过程。然后我有以下代码:

using (SqlConnection con = new SqlConnection(_connectionString))
{
    con.Open();

    using (SqlCommand cmd = new SqlCommand("GetModuleInstallerManifestXML", con))
    {
        cmd.CommandType = System.Data.CommandType.StoredProcedure;

        cmd.Parameters.Add(new SqlParameter("@mod_name", SqlDbType.VarChar, 250)).Value = this.ModuleName;

        using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
        {
            while (reader.Read())
            {
                manifestXmlList.Add(reader[]);
            }
        }
    }
}

我需要将xml数据逐行添加到列表中,然后将该列表写入文件,我该怎么做?

【问题讨论】:

    标签: c# sql-server xml ado.net


    【解决方案1】:

    检查这个答案https://stackoverflow.com/a/5424250/5358389

    string xmlString = string.Empty;
    using (XmlReader reader = cmd.ExecuteXmlReader())
    {            
         XDocument xml = XDocument.Load(reader);
         x.Save("filePath");
    }
    

    【讨论】:

    • 感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2021-09-20
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    相关资源
    最近更新 更多