簡體   English   中英

使用SqlDataReader讀取XML數據

[英]Reading XML Data using SqlDataReader

我有一個創建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數據逐行添加到列表中,然后將該列表寫入文件中,我該怎么做?

檢查此答案https://stackoverflow.com/a/5424250/5358389

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM