Concurrency violation: the UpdateCommand affected 0 records.
I have problem.
I can update the records in database from dataset.
It always have this error :
"Concurrency violation: the UpdateCommand affected 0 records."
This is a sample code:
ds=new DataSet();
ds.Clear();
try
{
cn=new MySqlConnection("/*connection string*/");
da=new MySqlDataAdapter();
selCommand=new MySqlCommand("SELECT * FROM books",cn);
da.SelectCommand=selCommand;
updCommand=new MySqlCommand("UPDATE books SET Title= @Title, Publisher= @Publisher, Lang= @Lang, Format= @Format "+
"WHERE ID= @ID",cn);
updCommand.Parameters.Add(new MySqlParameter("Title", MySqlDbType.VarChar, 45, "Title"));
updCommand.Parameters.Add(new MySqlParameter("Publisher", MySqlDbType.VarChar, 45, "Publisher"));
updCommand.Parameters.Add(new MySqlParameter("Lang", MySqlDbType.VarChar, 45, "Lang"));
updCommand.Parameters.Add(new MySqlParameter("Format", MySqlDbType.VarChar, 45, "Format"));
updCommand.Parameters.Add(new MySqlParameter("ID", MySqlDbType.Int32, 4, "ID"));
da.UpdateCommand=updCommand;
da.Fill(ds,"Books");
DataViewManager dvm=ds.DefaultViewManager;
dataGrid1.DataSource=dvm;
dataGrid1.DataMember="Books";
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
void Button1Click(object sender, System.EventArgs e)
{
da.Update(ds,"Books");
}