zoukankan      html  css  js  c++  java
  • 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+ "
     ";
                }
                //string xml = ds.GetXml(); 只读  不本地创建方法可以用
                //textBox1.Text = xml;
            }

    下面一种方法是带路径的默认路径

     private void button2_Click(object sender, EventArgs e)
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(@"C:UsersAdministratorDesktopPointManagementPoint.UIBook.xml");
                XmlNode root = xml.DocumentElement;
    
                textBox2.Text = "";
                for (int i = 0; i < root.ChildNodes.Count; i++)
                {
                    textBox2.Text = root.ChildNodes[i].ChildNodes[1].InnerText + "
    ";
                }
            }
  • 相关阅读:
    bzoj 2599
    bzoj 3697
    poj 1741
    bzoj 2741
    bzoj 5495
    bzoj 3261
    网络流24题——骑士共存问题 luogu 3355
    网络流24题——数字梯形问题 luogu 4013
    bzoj 3998
    网络流24题——魔术球问题 luogu 2765
  • 原文地址:https://www.cnblogs.com/yijieyufu/p/12230684.html
Copyright © 2011-2022 走看看