|
发表于 2020-1-4 22:42:01
|
显示全部楼层
sql = "delete from question where id=ChBox"
这个语句有问题吧, 你都没有给ID正确赋值, 数据库里根本没有id=ChBox这条数据. 你应该定一列藏的模板列,定义一个Label 帮定id字段,
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.id") %>'>
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
然后
Dim i As Integer
Dim ChBox As CheckBox
Dim label1 As Label
For i = 0 To DataGrid1.Items.Count - 1
ChBox = CType(DataGrid1.Items(i).Cells(0).FindControl("CheckBox1"), CheckBox)
label1 = CType(DataGrid1.Items(1).FindControl("label1"), Label)
If ChBox.Checked = True Then
Dim conn As New SqlConnection
conn.ConnectionString = "server=127.0.0.1;uid=sa;pwd=;database=netexam"
conn.Open()
Dim sql As String
sql = "delete from question where id='" + label1.Text + "'";
Dim cmd As New SqlCommand(sql, conn)
cmd.ExecuteNonQuery()
bind()
End If
Next
|
|