执行这段代码的删除功能报错“bof 或 eof 中有一个是真,或者当前的记录已被删除,所需的操作需要一个当前记录”

small_warm 2009-03-08 10:50:26
Private Sub Toolbar2_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL As String
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=family.mdb;Persist Security Info=False"
SQL = "select * from OutPutKind where 类型号='" & Text1.Text & "'"
rs.CursorLocation = adUseClient
rs.Open SQL, conn, adOpenKeyset, adLockPessimistic
Select Case Button.Key
Case "delete"
Dim answer As String
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then
DataGrid1.AllowDelete = True
rs.Delete
rs.Update
DataGrid1.Refresh
Else
Exit Sub
End If
Case "add"
If Trim(Text1.Text) = "" Then
MsgBox "编号不能为空", vbOKOnly + vbExclamation, ""
ElseIf Trim(Text2.Text) = "" Then
MsgBox "类型不能为空", vbOKOnly + vbExclamation, ""
Else
If rs.EOF Then
rs.AddNew
rs.Fields(0) = Trim(Text1.Text)
rs.Fields(1) = Trim(Text2.Text)
rs.Update
Set DataGrid1.DataSource = rs
MsgBox "添加成功!", vbOKOnly, ""
Text1.Text = ""
Text2.Text = ""
DataGrid1.Refresh
Else
MsgBox "类型号不能相同", vbOKOnly, ""
End If
End If
End Select
End Sub
...全文
663 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
饮水需思源 2009-03-08
  • 打赏
  • 举报
回复
'增加记录:conn.execute "insert into tablename(...) values(...)"
'修改记录:conn.execute "update tablename set ... where ..."
'删除记录:conn.execute "delete from tablaname where ..."
small_warm 2009-03-08
  • 打赏
  • 举报
回复
绑定rs 记录集
of123 2009-03-08
  • 打赏
  • 举报
回复
DataGrid 绑定的是什么?ADODC?

Private Sub Toolbar2_ButtonClick(ByVal Button As MSComctlLib.Button)
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL As String
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=family.mdb;Persist Security Info=False"

Select Case Button.Key
Case "delete"
Dim answer As String
answer = MsgBox("确定要删除吗?", vbYesNo, "")
If answer = vbYes Then

conn.Execute "Delete From OutPutKind where 类型号='" & Text2.Text & "'"
ADODC.Recordset.Requery
Else
Exit Sub
End If
Case "add"
If Trim(Text1.Text) = "" Then
MsgBox "编号不能为空", vbOKOnly + vbExclamation, ""
ElseIf Trim(Text2.Text) = "" Then
MsgBox "类型不能为空", vbOKOnly + vbExclamation, ""
Else
SQL = "select * from OutPutKind where 类型号='" & Text2.Text & "'"
Set rs = conn.Execute(SQL)
If rs.EOF
conn.Execute "Insert Into OutPutKind(编号, 类型号) Values('" & Text1.Text & "','" & Text2.Text & "')"
MsgBox "添加成功!", vbOKOnly, ""
Text1.Text = ""
Text2.Text = ""
ADODC.Recordset.Requery
Else
MsgBox "类型号不能相同", vbOKOnly, ""
End If
End If
End Select
End Sub
small_warm 2009-03-08
  • 打赏
  • 举报
回复
怎么没人帮忙啊

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧