无法删除datagridview中选定行(数据库中删除)
public static string str = "";private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (this.dataGridView1.SelectedRows.Count > 0)
str = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.OKCancel);
if (dr == DialogResult.OK)
{
if (str == "")
{
MessageBox.Show("请选择你要删除的行!", "警告", MessageBoxButtons.OKCancel);
return;
}
string sql = "delete from text1 where bh='" + str + "'";
str = "";
MessageBox.Show("该学生已被删除!", "提示");
}
str 没有取得值,一直弹出“请选择你要删除的行”,不知道怎么改