熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#中XML的寫入方法

2022-06-13   來源: .NET編程 

  

  using System;
        using SystemData;
        using SystemDataOleDb;
        namespace ConsoleDataSet
        {
            /// <summary>
            /// Class 的摘要說明
            /// </summary>
            class DataSetClass
            {
                /// <summary>
                /// 應用程序的主入口點
                /// </summary>
                [STAThread]
                static void Main(string[] args)
                {
                    string strCon = @Provider=MicrosoftJetOLEDB;Data Source=DataBasemdb;
                    // 定義連接
                    OleDbConnection MyCon = new OleDbConnection(strCon);
                    try
                    {
                        // 打開連接
                        MyConOpen();
                        string strSQL = @select * from ADODemo;
                        OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();
                        MyDataAdapterSelectCommand = new OleDbCommand(strSQL MyCon);
                        // 將數據填充到DataSet中
                        DataSet MyDataSet = new DataSet();
                        MyDataAdapterFill(MyDataSet ADODemo);
                        // 從DataSet中獲取DataTable
                        DataTable MyDataTable = MyDataSetTables[ADODemo];
                        // 設置姓名字段不能為空
                        MyDataTableColumns[姓名]AllowDBNull = false;
                        // 修改第一行的姓名
                        MyDataTableRows[][姓名] = 趙六;
                        MyDataTableRows[][姓名] = 張三;
                        // 添加一條新記錄
                        DataRow NewRow = MyDataTableNewRow();
                        NewRow[姓名] = 趙六;
                        NewRow[年齡] = ;
                        MyDataTableRowsAdd(NewRow);
                        foreach (DataRow row in MyDataTableRows)
                        {
                            ConsoleWriteLine(姓名:{} 年齡:{} row[姓名]ToString() row[年齡]ToString());
                        }
                        // 將DataSet中的數據更新到數據庫中
                        OleDbCommandBuilder MyCommandBuilder = new OleDbCommandBuilder(MyDataAdapter);
                        MyDataAdapterUpdate(MyDataSet ADODemo);
                    }
                    catch (Exception ex)
                    {
                        ConsoleWriteLine({} exToString());
                    }
                    finally
                    {
                        MyConClose();
                    }
                    ConsoleReadLine();
                }
            }
        }


From:http://tw.wingwit.com/Article/program/net/201311/11744.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.