VB中通过DataGrid1控件删除某一条记录,通过文本框活的用户输入需要删除记录的ID删除
这是输入ID为“1”后点击删除出现的情况:光标移至ID为“1”的记录行,并出现错误提示框,单机调试后出现下图:删除按钮代码为:PrivateSubCommand2_Cli...
这是输入ID为“1”后点击删除出现的情况:光标移至ID为“1”的记录行,并出现错误提示框,单机调试后出现下图:
删除按钮代码为:
Private Sub Command2_Click()
DataGrid1.AllowDelete = True
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\bike.mdb;Persist Security Info=False"
Adodc1.Visible = False
Recordset = "b1"
With Adodc1
.Recordset.Find "ID='" & Text1.Text & "'"
If Not Recordset.EOF And Not Recordset.BOF Then
Adodc1.RecordSource = "Delete * from b1 where ID=Text1.Text"
Adodc1.RecordSource = "update * from b1"
End If
End With
Adodc1.Recordset.MoveNext '移动数据库指针
Adodc1.Recordset.Delete ' 然后删除记录
Adodc1.Recordset.Update
End Sub 展开
删除按钮代码为:
Private Sub Command2_Click()
DataGrid1.AllowDelete = True
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\bike.mdb;Persist Security Info=False"
Adodc1.Visible = False
Recordset = "b1"
With Adodc1
.Recordset.Find "ID='" & Text1.Text & "'"
If Not Recordset.EOF And Not Recordset.BOF Then
Adodc1.RecordSource = "Delete * from b1 where ID=Text1.Text"
Adodc1.RecordSource = "update * from b1"
End If
End With
Adodc1.Recordset.MoveNext '移动数据库指针
Adodc1.Recordset.Delete ' 然后删除记录
Adodc1.Recordset.Update
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询