private void btnDelete_Click(object sender, EventArgs e)
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
C#中datagridview删除行 带更新数据库
最新推荐文章于 2022-08-06 20:04:25 发布