我要实现的功能为点击按钮后,读取AppConfig.DLL文件中的信息,查询出"SELECT * FROM PURTG WHERE TG013 = 'Y' AND TG003 <= '" + Data + "'",再把查询的结果保存为XML文件,请问要如何做?
private void button1_Click(object sender, EventArgs e)
{
string IPServer = "";
string Database = "";
string User ="";
string Password ="";
string Data = "";
Data = tbData.Text;
try
{
string AppPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
XDocument myXDoc = XDocument.Load(AppPath + "AppConfig.DLL");
XElement rootNode = myXDoc.Element("AppConfig");
foreach (XElement node in rootNode.Elements("Config"))
{
IPServer = node.Element("IPServer").Value;
Database = node.Element("Database").Value;
User = node.Element("User").Value;
Password = node.Element("password").Value;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
DataSet ds= new DataSet();
string sql = "SELECT * FROM PURTG WHERE TG013 = 'Y' AND TG003 <= '" + Data + "'";
using (SqlConnection sqlcon = new SqlConnection("server='" + IPServer + "';database='" + Database + "';uid='" + User + "';pwd='" + Password + "'"))
{
SqlDataAdapter adatapter = new SqlDataAdapter();
adatapter.SelectCommand = new SqlCommand(sql, sqlcon);
adatapter.Fill(ds);
}
this.dgvDataViewPURTG.DataSource = ds.Tables[0];
其中"SELECT * FROM PURTG WHERE TG013 = 'Y' AND TG003 <= '" + Data + "'"为查询语句。
程序界面我不想要dgvDataView显示,这里只做测试。
private void button1_Click(object sender, EventArgs e)
{
string IPServer = "";
string Database = "";
string User ="";
string Password ="";
string Data = "";
Data = tbData.Text;
try
{
string AppPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
XDocument myXDoc = XDocument.Load(AppPath + "AppConfig.DLL");
XElement rootNode = myXDoc.Element("AppConfig");
foreach (XElement node in rootNode.Elements("Config"))
{
IPServer = node.Element("IPServer").Value;
Database = node.Element("Database").Value;
User = node.Element("User").Value;
Password = node.Element("password").Value;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
DataSet ds= new DataSet();
string sql = "SELECT * FROM PURTG WHERE TG013 = 'Y' AND TG003 <= '" + Data + "'";
using (SqlConnection sqlcon = new SqlConnection("server='" + IPServer + "';database='" + Database + "';uid='" + User + "';pwd='" + Password + "'"))
{
SqlDataAdapter adatapter = new SqlDataAdapter();
adatapter.SelectCommand = new SqlCommand(sql, sqlcon);
adatapter.Fill(ds);
}
this.dgvDataViewPURTG.DataSource = ds.Tables[0];
其中"SELECT * FROM PURTG WHERE TG013 = 'Y' AND TG003 <= '" + Data + "'"为查询语句。
程序界面我不想要dgvDataView显示,这里只做测试。
ds.tables[0].WriteXML("文件路径");
错误 1 “System.Data.DataTable”不包含“WriteXML”的定义,并且找不到可接受类型为“System.Data.DataTable”的第一个参数的扩展方法“WriteXML”(是否缺少 using 指令或程序集引用?) E:\C#\DataDivision\DataDivision.cs 63 34 DataDivision