Access数据库不使用表适配器和DataBinding更新或插入或删除C#

时间:2016-12-20 13:05:32

标签: c# data-binding datagridview access tableadapter

我正在尝试使用表适配器更新我的访问文件。 当我添加数据时,我的DataGridview显示已添加或删除数据 但是,当我检查我的访问文件时,它保持不变 这是没有编译错误或没有异常错误 这是以下代码 This is the Image of the Data Grid View ....

  private void adminFlights_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'appData.Airline' table. You can move, or remove it, as needed.
        this.airlineTableAdapter.Fill(this.appData.Airline);
        airlineBindingSource.DataSource = this.appData.Airline;

    }

 private void dataGridView2_KeyDown(object sender, KeyEventArgs e)
    {//TO delete data from Data Grid view
        if (e.KeyCode == Keys.Delete)
        {
            MessageBox.Show(e.KeyCode.ToString());
            if (MessageBox.Show("Are You Sure You want TO Delete ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                airlineBindingSource.RemoveCurrent();
             }}}




   private void btnSave_Click(object sender, EventArgs e)
    {//this the Button i am using save the Data into acess using DatagridView

        try
        {
            dataGridView2.DataSource = airlineBindingSource.DataSource;

            airlineBindingSource.EndEdit();
            airlineTableAdapter.Update(this.appData.Airline);

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
        }
    }


  private void Add_flights_Click(object sender, EventArgs e)
    {
        try
        {
            panel.Enabled = true;
            Airline_add.Focus();
            this.appData.Airline.AddAirlineRow(this.appData.Airline.NewAirlineRow());
            airlineBindingSource.MoveLast();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
            airlineBindingSource.ResetBindings(false);
        }
    }

0 个答案:

没有答案