Hi All,

I'm having a problem updating DataSource using DataAdapter.Update method. I have an app that allows user to read data from the database and display it on the DataGridView. The user can insert, delete, update the data in DataGridView and hit the "Update" button to save the changes.

Below is the listing of my code:

string dbConString = "Data Source = MYVISTA\\SQLEXPRESS; Initial Catalog = ChinChinDB; Integrated Security = SSPI";

string dbUpdate = "UPDATE " + txtTable.Text + " SET Dish = @Dish, Price = @Price, Description = @Description WHERE Dish = @Dish";
string dbInsert = "INSERT INTO " + txtTable.Text + " (Dish, Price, Description) VALUES (@Dish, @Price, @Description)";
string dbDelete = "DELETE FROM " + txtTable.Text + " WHERE Dish = @Dish";

con.ConnectionString = dbConString;

daGetTables.UpdateCommand = cmdUpdate;
daGetTables.InsertCommand = cmdInsert;
daGetTables.DeleteCommand = cmdDelete;

daGetTables.UpdateCommand.CommandText = dbUpdate;
daGetTables.UpdateCommand.Connection = con;
daGetTables.UpdateCommand.Parameters.Add("@Dish", SqlDbType.VarChar, 50, "Dish");
daGetTables.UpdateCommand.Parameters.Add("@Price", SqlDbType.Float, 10, "Price");
daGetTables.UpdateCommand.Parameters.Add("@Description", SqlDbType.VarChar, 200, "Description");

daGetTables.InsertCommand.CommandText = dbInsert;
daGetTables.InsertCommand.Connection = con;
daGetTables.InsertCommand.Parameters.Add("@Dish", SqlDbType.VarChar, 50, "Dish");
daGetTables.InsertCommand.Parameters.Add("@Price", SqlDbType.Float, 10, "Price");
daGetTables.InsertCommand.Parameters.Add("@Description", SqlDbType.VarChar, 200, "Description");

daGetTables.DeleteCommand.CommandText = dbDelete;
daGetTables.DeleteCommand.Connection = con;
daGetTables.DeleteCommand.Parameters.Add("@Dish", SqlDbType.VarChar, 50, "Dish");

try
{
daGetTables.Fill(dtTables);
daGetTables.Update(dtTables);
}
catch(SqlException sqlEx)
{
lboxActivities.Items.Add(rowCountUpdateTables + ". " + sqlEx.Message.ToString());
rowCountUpdateTables++;
}
finally
{
//Do Something
}
------------------------------------------------------------------------

Insert and Delete are working fine, except Update. Whenever a row is updated and the update button is clicked, I get a "DBConcurrencyException" error.

Does anybody know what I'm missing?