C#用DataSet操作Xml的代碼

來源:互聯網
上載者:User
/*
 * ? 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檔案的完整例子上來的~

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.