我正在编写以下代码:
namespace WebApplication5
{
public partial class WebForm1 : System.Web.UI.Page
{
private DataSet dataset1 = new DataSet();
OleDbDataAdapter adapter;
public DataSet ds
{
get { return dataset1; }
set { dataset1 = value; }
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\jayant\Documents\User_Details.accdb";
con.Open();
adapter = new OleDbDataAdapter("Select * from User_Details",con);
adapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
// ds.WriteXml("C:\\MyUser_Details.xml"); If I do this here it writes data
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
ds.WriteXml("C:\\MyUser_Details.xml");
// no data in xml files, just root tags
}
}
}
这里我的 DataSet 变量是全局变量,但是当我单击 button2 时,它不会向输出 XML 文件发送任何数据。你能告诉我为什么吗?或者我应该进行哪些修改来执行此操作?
谢谢