大家看看2段代码有什么区别,我看了半天也没有看出来,未注销的是不对的,注销的正确
sqlcon = new SqlConnection(strCon);
SqlCommand sqlcom;
for (int i = 0; i < GridView1.Rows.Count - 1; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
string sqlstr = "delete from tb_Member where id='" + GridView1.DataKeys[i].Value + "'";
sqlcom = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
sqlcon.Close();
}
}
bind();
//sqlcon = new SqlConnection(strCon);
//SqlCommand sqlcom;
//for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
//{
// CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
// if (cbox.Checked == true)
// {
// string sqlstr = "delete from tb_Member where id='" + GridView1.DataKeys[i].Value + "'";
// sqlcom = new SqlCommand(sqlstr, sqlcon);
// sqlcon.Open();
// sqlcom.ExecuteNonQuery();
// sqlcon.Close();
// }
//}
//bind();