Click to See Complete Forum and Search --> : Concurrency violation: the UpdateCommand affected 0 records.


beeper
April 16th, 2005, 08:14 AM
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 code sample:

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");
}

what am a doing wrong?

beeper
April 17th, 2005, 10:35 AM
Anyone can help? Just say what this error mean?
I search everyware aswer for my question, but i can find a solution. Please, what i doing wrong. Do a need change something from server side? The code looks ok, i dont have experience with c# and ado.net.

beeper
April 17th, 2005, 05:56 PM
solution:)

selCommand=new MySqlCommand("SELECT Title, Publisher, Lang, Format, ID FROM books",cn);

MySqlCommandBuilder builder=new MySqlCommandBuilder(da);

da.SelectCommand=selCommand;
da.InsertCommand=builder.GetInsertCommand();
da.UpdateCommand=builder.GetUpdateCommand();
da.DeleteCommand=builder.GetDeleteCommand();

ifungus
February 26th, 2006, 04:45 PM
Hi, I just save a bunch of time by reading this Post:-)

Thx again for posting!