karlmoscow
New Member
I have added a DataGridView item from the DataSource toolbox to a form.I would like the changes made by the user to the DataGridView (edit / delete only) to update the Database when the user clicks the save button.When I run the application and try the code below, the message box confirms no errors occurred during the call of the save method, however the changes are not saved to the Database.Any Ideas?Much appreciated.Form
Form code:\[code\]public partial class EditUsers : Form{ public EditUsers() { InitializeComponent(); } private void EditUsers_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'debenhamsProjectOfficeDatabaseDataSet.Users' table. You can move, or remove it, as needed. this.usersTableAdapter.Fill(this.debenhamsProjectOfficeDatabaseDataSet.Users); } private void usersBindingNavigatorSaveItem_Click(object sender, EventArgs e) { try { this.Validate(); this.usersBindingSource.EndEdit(); this.tableAdapterManager.UpdateAll(this.debenhamsProjectOfficeDatabaseDataSet); string connection = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DebenhamsProjectOfficeDatabase.mdf;Integrated Security=True;User Instance=True"; SqlConnection cn = new SqlConnection(connection); SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Users", cn); cn.Open(); adapter.Fill(this.debenhamsProjectOfficeDatabaseDataSet); adapter.Update(this.debenhamsProjectOfficeDatabaseDataSet); MessageBox.Show("Update successful"); cn.Close(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }}\[/code\]