天天看點

資料庫通路控件示例

需要自己利用VS手動添加資料源

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 資料庫通路控件示例
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        //單擊導航工具欄上的“儲存”按鈕時執行以下事件處理程式
        private void 雇員BindingNavigatorSaveItem_Click_1(object sender, EventArgs e)
        {
            this.Validate();    //驗證控件的值
            this.雇員BindingSource.EndEdit(); //将挂起的更改應用于基礎資料源
            this.tableAdapterManager.UpdateAll(this.northwindDataSet);//儲存所有資料表中的所有資料
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 這行代碼将資料加載到表“northwindDataSet.雇員”中。您可以根據需要移動或删除它。
            //調用雇員TableAdapter的主方法來填充類型化資料集對象northwindDataSet的"雇員"表
            this.雇員TableAdapter.Fill(this.northwindDataSet.雇員);

        }
    }
}