- Joined
- Jun 16, 2008
- Messages
- 1
- Reaction score
- 0
ON FORM LOAD
odbcDataAdapter = new OdbcDataAdapter(@"call Get_Designers(-1)", sqlConnection.Connection);
dataTable = new DataTable();
odbcDataAdapter.Fill(dataTable);
//odbcDataAdapter.FillSchema(dataTable, SchemaType.Source);
OdbcCommandBuilder commandBuilder = new OdbcCommandBuilder(odbcDataAdapter);
BindingSource bSource = new BindingSource();
bSource.DataSource = dataTable;
dataGridView.DataSource = bSource;
DesignerName.DataPropertyName = "designer_name";
DesignerContact.DataPropertyName = "designer_contact";
DesignerLastModified.DataPropertyName = "last_modified";
DesignerDateCreated.DataPropertyName = "date_added";
ON SAVE BUTTON CLICK //TRIGGERED AFTER CHANGES IN ONE OR MORE DATA ROW IN GRID
OdbcCommand updateCmd = new OdbcCommand(@"call Set_Designer(@designer_id,@designer_name,@designer_contact)");
updateCmd.Parameters.Add("@designer_id", OdbcType.Int, 11, "designer_id");
updateCmd.Parameters.Add("@designer_name", OdbcType.VarChar, 255, "designer_name");
updateCmd.Parameters.Add("@designer_contact", OdbcType.VarChar, 500, "designer_contact");
odbcDataAdapter.UpdateCommand = updateCmd;
odbcDataAdapter.Update(dataTable.GetChanges(DataRowState.Modified));
GIVES EXCEPTION
System.Data.DBConcurrencyException: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.
odbcDataAdapter = new OdbcDataAdapter(@"call Get_Designers(-1)", sqlConnection.Connection);
dataTable = new DataTable();
odbcDataAdapter.Fill(dataTable);
//odbcDataAdapter.FillSchema(dataTable, SchemaType.Source);
OdbcCommandBuilder commandBuilder = new OdbcCommandBuilder(odbcDataAdapter);
BindingSource bSource = new BindingSource();
bSource.DataSource = dataTable;
dataGridView.DataSource = bSource;
DesignerName.DataPropertyName = "designer_name";
DesignerContact.DataPropertyName = "designer_contact";
DesignerLastModified.DataPropertyName = "last_modified";
DesignerDateCreated.DataPropertyName = "date_added";
ON SAVE BUTTON CLICK //TRIGGERED AFTER CHANGES IN ONE OR MORE DATA ROW IN GRID
OdbcCommand updateCmd = new OdbcCommand(@"call Set_Designer(@designer_id,@designer_name,@designer_contact)");
updateCmd.Parameters.Add("@designer_id", OdbcType.Int, 11, "designer_id");
updateCmd.Parameters.Add("@designer_name", OdbcType.VarChar, 255, "designer_name");
updateCmd.Parameters.Add("@designer_contact", OdbcType.VarChar, 500, "designer_contact");
odbcDataAdapter.UpdateCommand = updateCmd;
odbcDataAdapter.Update(dataTable.GetChanges(DataRowState.Modified));
GIVES EXCEPTION
System.Data.DBConcurrencyException: Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.