2017-02-01 75 views
0

我正在嘗試創建一個按鈕,將數據保存到數據庫。數據將在SuperGridControl中編輯或引入。我完全不知道該怎麼做。有什麼建議麼?保存按鈕在WinFormApp SuperGridControl

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; 
using System.Data.SqlClient; 

     namespace MyFirstWinForApp { 
     public partial class Users : Form 
     { 

      public Users() 
      { 
       InitializeComponent(); 
      } 

      private void Form1_Load(object sender, EventArgs e) 
      { 
       // TODO: This line of code loads data into the 'testDataSet.GrupyUzytkownikow' table. You can move, or remove it, as needed. 
       this.grupyUzytkownikowTableAdapter.Fill(this.testDataSet.GrupyUzytkownikow); 
       // TODO: This line of code loads data into the 'testDataSet.Uzytkownicy' table. You can move, or remove it, as needed. 
       this.uzytkownicyTableAdapter.Fill(this.testDataSet.Uzytkownicy); 


      } 

      private void button1_Click(object sender, EventArgs e) 
      { 
       try 
       { 
        !!!!!!!!!!!!!!!!!!!!! 
        MessageBox.Show("Dane zapisane", "Zapisano", MessageBoxButtons.OK, MessageBoxIcon.Information); 
       } 
       catch (Exception ex) 
       { 
        MessageBox.Show(ex.Message, "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); 
       } 
      } 

     } } 

回答

0

Button_Click事件,您需要檢查以下

  1. 做一個檢查,以驗證網格是空的,用 綁定新的數據吧。
  2. 如果Grid不是空的,有一些數據,你需要 排除重複數據由內Grid內的 dataset/datatable與數據進行比較的數據和網格中添加獨特的數據 。