For i = 0 To GridView1.Rows.Count - 1
Dim chkbox As CheckBox = CType(GridView1.Rows(i).FindControl("chechbox1"), CheckBox)
If chkbox.Checked = True Then
Dim str As String = "delete from info where id=" & GridView1.DataKeys(i).Value
Dim cmd As New OleDbCommand(str, cn)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End If
红色为出错行:提示对象为初使化。用 new 也不行的。
在C#下:好用
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
string dele = "delete from users where userid='" + GridView1.DataKeys[i].Value + "'";
SqlCommand cmd = new SqlCommand(dele, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
}
Dim chkbox As CheckBox = CType(GridView1.Rows(i).FindControl("chechbox1"), CheckBox)
If chkbox.Checked = True Then
Dim str As String = "delete from info where id=" & GridView1.DataKeys(i).Value
Dim cmd As New OleDbCommand(str, cn)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End If
红色为出错行:提示对象为初使化。用 new 也不行的。
在C#下:好用
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
if (cbox.Checked == true)
{
string dele = "delete from users where userid='" + GridView1.DataKeys[i].Value + "'";
SqlCommand cmd = new SqlCommand(dele, cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
}
}
Dim chkbox As CheckBox = CType(GridView1.Rows(i).FindControl("chechbox1"), CheckBox)
If chkbox.Checked = True Then
Dim str As String = "delete from info where id=" & GridView1.DataKeys(i).Value
Dim cmd As New OleDbCommand(str, cn) //很明显这块有问题
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End If
=====
看看后面的chechbox1是不是拼错了,估计是
Dim chkbox As CheckBox = CType(GridView1.Rows(i).FindControl("CheckBox1"), CheckBox)