你用什么打开的 Xml文件?用记事本试一试

解决方案 »

  1.   

    UE9,NOTEPAD都用了啊。就是乱码
      

  2.   

    给你一下例子,你新建一个页,在page_load事件里写下面的代码,但你机子上要装有sql server,sa用户的密码为空,且根目录要有权限写:
    private void Page_Load(object sender, System.EventArgs e)
    { SqlConnection sc=new SqlConnection("server=localhost;database=northwind;user id=sa;password=");
    sc.Open();
    SqlCommand scd=new SqlCommand("SELECT ProductID, ProductName FROM Products WHERE CategoryID = 1 ORDER BY ProductID",sc);
    SqlDataAdapter sda=new SqlDataAdapter(scd);
    DataSet ds=new DataSet();
    sda.Fill(ds,"product");
    sc.Close(); XmlTextWriter writer;
    String filepath = Server.MapPath("test3.xml");
    writer = new XmlTextWriter(filepath,Encoding.UTF8);
    writer.WriteStartDocument();
    ds.WriteXml(writer);
    writer.Close();
    Page.Response.Redirect("test3.xml");

    }
      

  3.   

    sqlConn1.ConnectionString = SystemConfig.ConnectionString;
    sqlDataAdapter1.SelectCommand = new System.Data.SqlClient.SqlCommand();
    sqlDataAdapter1.SelectCommand.Connection = sqlConn1;
    sqlDataAdapter1.SelectCommand.CommandText = "select id,topicreplayid,topicname,topicauthname,TopicSendDate,TopicBody from TopicList where id=@TopicID or topicreplayid=@TopicID";
    sqlDataAdapter1.SelectCommand.Parameters.Add("@TopicID",topicid);
    sqlConn1.Open();
    sqlDataAdapter1.Fill(ds1);
    DataGrid1.DataSource = ds1;
    DataGrid1.DataBind();
    ds1.WriteXml("c:\\a.xml");我的代码是这样
      

  4.   

    用下面读取流的方法试试,然后检查a.xml的schema中msdata:Locale="zh-CN":
    fin = new FileStream(Server.MapPath("a.xml"),FileMode.Create,FileAccess.ReadWrite, FileShare.ReadWrite);
    ds.WriteXml(fin, XmlWriteMode.WriteSchema);
    fin.Close();