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

C# WinForm 讀寫XML文件

2022-06-13   來源: ASP編程 

  建立一個WinForm應用程序 添加MenuStrip控件填寫兩個功能讀取導出數據

  用了兩個DataSet控件和對話框打開(OpenFilesDialog控件)保存(SaveFilesDialog控件)

  讀取                  private void 讀取ToolStripMenuItem_Click(object sender EventArgs e)
                {
                     if (opFileDlg ShowDialog() == DialogResultOK)
                    {
                         if(opFileDlg OpenFile()!=null)
                         {
                             twoXML ReadXml (@opFileDlg FileName );
                             foreach (DataRow twoRow in twoXML Tables [user]Rows)
                             {
                                DataRow newRow = dsXMLTables[user]NewRow();
                                newRow [序號]  = twoRow [序號];
                                newRow[標題] = twoRow[標題];
                                newRow[網址] = twoRow[網址];
                                newRow[用戶名] = twoRow[用戶名];
                                newRow[密碼] = twoRow[密碼];
                                newRow[時間] = twoRow[時間];
                                newRow[備注] = twoRow[備注];
                                dsXML Tables [user]Rows Add(newRow);
                             }
                             int n = dsXML Tables [user]Rows Count ;
                             for(int i=;i<n;i++)
                             {
                                 dsXML Tables [user]Rows [i][序號]=i+;
                             }
                             dsXMLWriteXml(@userxml);
                             thisVisible = true;
                             MessageBoxShow(數據導入成功! 成功);
                         }
                    }
                    else
                    {
                       thisVisible  = true;
                    }
                }
        導出

  private void 導出ToolStripMenuItem_Click(object sender EventArgs e)
                {
                    if (svFileDlgShowDialog() == DialogResultOK)
                    {
                        dsXMLWriteXml(@svFileDlgFileName);
                        thisVisible = true;
                        MessageBoxShow(數據導出成功! 成功);
                    }
                    else
                    {
                       thisVisible  = true;
                    }
                }


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