11
I am trying to delete a record from a datagridview then updating it to a mysql server, however I keep receiving "Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.". I have googled and messed around with it somewhat and cannot figure out a fix for love nor money. Where am I going wrong?
private void Form1_Load(object sender, EventArgs e)
{
try
{
// create a connection to the server
connection = new MySqlConnection("SERVER=" + Constants.SERVER + ";" + "DATABASE=" + Constants.DATABASE + ";UID=" + Constants.USERNAME + ";" + "PASSWORD=" + Constants.PASSWORD + ";");
connection.Open();
// create our default handler
adapter = new MySqlDataAdapter();
// set the default commands to do
adapter.SelectCommand = new MySqlCommand("SELECT * FROM npc_drops", connection);
MySqlCommand query = new MySqlCommand("DELETE FROM npc_drops WHERE id = @id", connection);
query.Parameters.Add("@id", MySqlDbType.Int32, 10, "id");
adapter.DeleteCommand = query;
// create a table to put our data in and fill it with the results
table = new DataTable();
adapter.Fill(table);
// bind both the data table and the datagridview togeather
BindingSource source = new BindingSource();
source.DataSource = table;
dataGridView1.DataSource = source;
dataGridView1.Columns["id"].Visible = false;
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
table = table.GetChanges();
adapter.Update(table);
}
catch (MySqlException ex)
{
MessageBox.Show(ex.Message);
}
}
Table:
CREATE TABLE `n