I have a datagridview control and want to save changes made in the grid to the database.
This ia my code which doesn't work. Your thoughts.
private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
string Msg = "Requested changes have been made to the database.";
lblInstructions.Text = Msg ;
this.Validate();
this.customersBindingSource.EndEdit();
this.customersTableAdapter.Update(this.northwindDataSet.Customers);
}

Paul LoughridgePosted Apr 10, 2008, 5:58 PM
This is all of the code:
using
System;using
System.Collections.Generic;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Text;using
System.Windows.Forms;namespace
CustomerMaintenance{
public partial class CustomerMaintenanceForm : Form{
public CustomerMaintenanceForm(){
InitializeComponent();
}
private void customersBindingNavigatorSaveItem_Click(object sender, EventArgs e){
string Msg = "Requested changes have been made to the database.";lblInstructions.Text = Msg ;
this.Validate(); this.customersBindingSource.EndEdit(); this.customersTableAdapter.Update(this.northwindDataSet.Customers);}
private void CustomerMaintenanceForm_Load(object sender, EventArgs e){
// TODO: This line of code loads data into the 'northwindDataSet.Customers' table. You can move, or remove it, as needed. this.customersTableAdapter.Fill(this.northwindDataSet.Customers); this.Top=20; this.Left = this.Top; this.lblInstructions.Text = "";}
private void btnExit_Click(object sender, EventArgs e){
Close();
}
private void customersDataGridView_CellEndEdit(object sender, DataGridViewCellEventArgs e){
lblInstructions.Text =
"";customersDataGridView.Rows[e.RowIndex].ErrorText =
"";}
private void customersDataGridView_DataError(object sender, DataGridViewDataErrorEventArgs e){
lblInstructions.Text =
"Invalid input. Re-enter";customersDataGridView.Rows[e.RowIndex].ErrorText =
"Invalid input. Re-enter";e.Cancel =
true;}
}
}
Bechir BejaouiPosted Apr 10, 2008, 5:32 PM