Tôi đang cố gắng xóa bản ghi từ datagridview rồi cập nhật nó lên máy chủ mysql, tuy nhiên tôi tiếp tục nhận được "Vi phạm đồng thời: DeleteCommand bị ảnh hưởng 0 trong số 1 bản ghi dự kiến ". Tôi đã googled và messed xung quanh với nó một chút và không thể tìm ra một sửa chữa cho tình yêu cũng không tiền. Tôi làm sai ở đâu?Vi phạm đồng thời: DeleteCommand bị ảnh hưởng 0 trong số 1 hồ sơ dự kiến
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);
}
}
Bảng:
CREATE TABLE `npc_drops` (
`id` INT(10) NULL AUTO_INCREMENT,
`npcs` VARCHAR(250) NULL DEFAULT NULL,
`rate` INT(3) NULL DEFAULT NULL,
`item` INT(5) NULL DEFAULT NULL,
`amount` INT(10) NULL DEFAULT NULL,
PRIMARY KEY (`id`)
)
http: // stackoverflow .com/questions/6111961/mysql-limit-on-delete-statement kiểm tra điều này – BizApps
@BizApps cảm ơn bạn Tôi đã cập nhật dòng đó, nhưng vẫn nhận được cùng một lỗi đáng sợ! –
- bảng của bạn có sử dụng INNODB hoặc MYISAM không? - bạn có đang sử dụng tự động không? – Sebas