C#用DataSet操作Xml的代码
/*
* ? SharpDevelop ???
* ??: Administrator
* ??: 2008-1-9
* ??: 17:18
*
* ??????????,?????“?? | ?? | ?? | ??????”?
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Data;
namespace test
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void MainFormLoad(object sender, EventArgs e)
{
}
void MainFormFormClosing(object sender, FormClosingEventArgs e)
{
// FileStream fs = new FileStream("c:\\a.xml", FileMode.Create);
//dataSet1.WriteXml("c:\\b.xml");
//dataSet1.AcceptChanges();
//DataSet ds2 = new System.Data.DataSet();
//ds2.ReadXml(
//this.dataSet1.WriteXml(fs);
//fs.Close();
}
void Button1Click(object sender, EventArgs e)
{
dataSet1.ReadXml("c:\\b.xml");
// System.Data.DataColumn[] dcColl = new System.Data.DataColumn[2];
// dcColl[0] = new System.Data.DataColumn("Column1");
// dcColl[1] = new System.Data.DataColumn("Column2");
// this.dataSet1.Tables.Add("table1");
// this.dataSet1.Tables["table1"].Columns.AddRange(dcColl);
this.dataGrid1.DataSource = this.dataSet1;
}
void Button2Click(object sender, EventArgs e)
{
//textBox1.Text = dataSet1.GetXml();
}
}
}
如题。。
写的比较粗糙,以前一直用System.Xml的
发现这种方式更好~
用空会整理整理,写个完整的创建、读取、修改Xml文件的完整例子上来的~
* ? SharpDevelop ???
* ??: Administrator
* ??: 2008-1-9
* ??: 17:18
*
* ??????????,?????“?? | ?? | ?? | ??????”?
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Data;
namespace test
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void MainFormLoad(object sender, EventArgs e)
{
}
void MainFormFormClosing(object sender, FormClosingEventArgs e)
{
// FileStream fs = new FileStream("c:\\a.xml", FileMode.Create);
//dataSet1.WriteXml("c:\\b.xml");
//dataSet1.AcceptChanges();
//DataSet ds2 = new System.Data.DataSet();
//ds2.ReadXml(
//this.dataSet1.WriteXml(fs);
//fs.Close();
}
void Button1Click(object sender, EventArgs e)
{
dataSet1.ReadXml("c:\\b.xml");
// System.Data.DataColumn[] dcColl = new System.Data.DataColumn[2];
// dcColl[0] = new System.Data.DataColumn("Column1");
// dcColl[1] = new System.Data.DataColumn("Column2");
// this.dataSet1.Tables.Add("table1");
// this.dataSet1.Tables["table1"].Columns.AddRange(dcColl);
this.dataGrid1.DataSource = this.dataSet1;
}
void Button2Click(object sender, EventArgs e)
{
//textBox1.Text = dataSet1.GetXml();
}
}
}
如题。。
写的比较粗糙,以前一直用System.Xml的
发现这种方式更好~
用空会整理整理,写个完整的创建、读取、修改Xml文件的完整例子上来的~