我可以从 datagridview 中删除行,但不能在带有查询代码的 sql 表中。所以基本上我的“字符串查询”代码给出了一个错误。
https://imgur.com/2fn1RCf https://imgur.com/IMc7gBV
private void removebtn_Click(object sender, EventArgs e)
{
connection.Open();
int i;
i = dataGridView1.SelectedCells[0].RowIndex;
string query = "DELETE FROM PatientRecords WHERE Id=" + dataGridView1.SelectedRows[i].Cells[0].Value.ToString() + "";
SqlCommand delcmd = new SqlCommand(query, connection);
delcmd.ExecuteNonQuery();
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[i].Index);
MessageBox.Show("Selected Save Deleted");
}