下面是代码:
string str1 = this.button3.Text;
//判断是否选中行
if(dataGridView1.SelectedRows.Count>0)
{
}
else
{
MessageBox.Show("请选择要删除的行");
return;
}
//获取输入的信息
string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
//删除操作
string strsql = "selete * from kqlog where id='" + id + "'";
// 添加异常处理
try
{
SqlConnection con = GetCon();
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = strsql;
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
this.toolStripStatusLabel1.Text = "操作成功 !";
}
con.Close();
shuxin();
}
catch (Exception ex)
{
this.toolStripStatusLabel1.Text = "操作失败!失败原因:" + ex.Message;
}
该怎么改?