Dataset数据的XML持久化处理
主要方法是用ADO.NET的DataTale 填充到Dataset
Dataset 内置了XML持久化的方法,WriteXML和ReadXML:简单的WinFrom实例:从数据库的表
private void button1_Click(object sender, EventArgs e) { string path = AppDomain.CurrentDomain.BaseDirectory+"Users.xml";//BIN/DEBUGA string sql = "SELECT * FROM Users"; DataTable td = DBHelper.Query(sql, null); DataSet ds = new DataSet();//查询填充DATABLE到DTAASET ds.Tables.Add(td); ds.WriteXml(path);//保存到本地 XmlDocument xmld = new XmlDocument(); xmld.Load(path); XmlNode root = xmld.DocumentElement; label1.Text = ""; for (int i = 0; i < root.ChildNodes.Count; i++) { label1.Text = root.ChildNodes[i].InnerText+ "\r\n "; } //string xml = ds.GetXml(); 只读 不本地创建方法可以用 //textBox1.Text = xml; }
下面一种方法是带路径的默认路径
private void button2_Click(object sender, EventArgs e) { XmlDocument xml = new XmlDocument(); xml.Load(@"C:\Users\Administrator\Desktop\PointManagement\Point.UI\Book.xml"); XmlNode root = xml.DocumentElement; textBox2.Text = ""; for (int i = 0; i < root.ChildNodes.Count; i++) { textBox2.Text = root.ChildNodes[i].ChildNodes[1].InnerText + "\r\n"; } }
相关推荐
jackbon 2020-08-17
flyDeDog 2020-08-06
bluetears 2020-07-28
zghover 2020-07-28
powrexly 2020-07-20
pengpengflyjhp 2020-07-19
zwt00 2020-07-05
sunzxh 2020-07-05
anglehearts 2020-07-05
mengtianbao 2020-06-26
dongCSDN 2020-06-16
王道革 2020-06-14
litterfrog 2020-06-14
jokewinl 2020-06-10
loviezhang 2020-06-08
loveandroid0 2020-06-08
天空一样的蔚蓝 2020-06-04
dongCSDN 2020-06-03
dongCSDN 2020-06-01