为什么输出xml文件为空?

SUT*_*SUT 0 c# xml dataset

我试图通过从数据集中提取数据来输出XML文件.但是,xml文件始终为空.你能帮我找一下代码中的错误吗?

class Program
{
    static void Main(string[] args)
    {
        string umail = "";
        XDocument loaded = XDocument.Load(@"C:\1.xml");

        var q = from c in loaded.Descendants("AdminUserDB.dbo.U_User")
                select (string)c.Element("URI");

        foreach (string em in q)
            umail = em;

        SqlConnection cn = new SqlConnection("server=(local);database=AdminUserDB;Persist Security Info=True; uid=sa;pwd=P@swrd123");
        cn.Open();

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM dbo.U_User WHERE URI=@umail", cn);

        da.SelectCommand.Parameters.AddWithValue("@umail", umail);

        da.Fill(ds);

        string filename = "output.xml";

        System.IO.FileStream myFileStream = new System.IO.FileStream(filename, System.IO.FileMode.Create);

        System.Xml.XmlTextWriter myXmlWriter = new System.Xml.XmlTextWriter(myFileStream, System.Text.Encoding.Unicode);

        ds.WriteXml(myXmlWriter);

        myXmlWriter.Close();

        cn.Close();

    }
}
Run Code Online (Sandbox Code Playgroud)

}

我也试图直接使用DataSet.WriteXml方法,但是,我找不到应引用哪个命名空间.我在MSDN上搜索了WriteXml,但是我找不到System.Data.DataSet命名空间,它在WriteXml方法页面上列出.

谢谢

SUT

Adi*_* Jr 5

你应该调用Flush方法.