This is a pretty small program, so I just used the autogenerated code for my datasource and dragged/dropped a datagridview on my WinForm. I’m trying to manually update a column in a row, but it fails each time I get to the “UpdateAll” of my tablemanager. Here’s my code for double click of cell content:
private void dgv1DataGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
string delMemberID = dgv1DataGridView.Rows[e.RowIndex].Cells[0].Value.ToString();
ds1DataSet.Table1.Rows[ds1DataSet.Table1.Rows.IndexOf(ds1DataSet.Table1.FindByMemberID(delMemberID))][9] = MemberID.ToString();
this.Validate();
this.bs1BindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.ds1DataSet);
MessageBox.Show("Replacement Successful");
this.Close();
}
catch
{
MessageBox.Show("Replacement Failed");
}
}
My expectations are; when a user double clicks anywhere inside a row of the datagridview, it will update that row with a different “MemberID” for that column, save the data everywhere (including database), and then close the form (to return the parent form).
For some reason, my tableAdapterManager wasn’t linked to my TableAdapter on that form – once I linked them, the above code worked fine.
To be more precise, I clicked on the design view of my form and clicked the the tableAdapterManager at the bottom of the design window. Then looking in the “Properties” window, I noticed that the TableAdapter was blank (if you used a wizard to create the DataSource, then it will be named the same as the table in your DataSource). Once I selected the correct name for the TableAdapter, everything worked perfect.