ADO及DataGrid中要运用到一系列的操作,在对某条记录删除时,有误,高手帮忙,在线等!

ywxbutterfly 2003-08-20 10:34:02
我用DataGrid显示数据,结合ADO,在对某条记录删除时,总会提示“句柄有误……”各位高手请帮忙,我是用ToolBar来操作的,若哪位有源代码的,可以贴过来,谢谢!
...全文
32 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
seagullflying 2004-02-11
  • 打赏
  • 举报
回复
to : sdgqx(小飞侠)
没错 直接 rs.delete 即可
cloudtarget 2004-02-07
  • 打赏
  • 举报
回复
用设置断点跟踪一下执行顺序便知
ywxbutterfly 2003-08-21
  • 打赏
  • 举报
回复
我加了下列代码:
Private Sub MaterialAdo_WillMove(ByVal adReason As ADODB.EventReasonEnum, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error Resume Next
End Sub
但是运行时出现:编译错误,提示为:过程声明与同名事件或过程的描述不匹配。
不知道是为什么,不知所措。
iiboy 2003-08-21
  • 打赏
  • 举报
回复
这个问题较为少见,但是你可以试试看将其中的On Error Resum next改为On Error Goto 该程序段中的某个标号.顺便检查一下看是否真的有同名子程序段存在.
至于上面的DBGRID出错,我想可能是ADO控件没有刷新,试试将ado刷新看看.
看能否用Adodc1_Error(...)事件能否解决.
ywxbutterfly 2003-08-20
  • 打赏
  • 举报
回复
我的代码如下,请高手帮忙改一下,现在实现起来是删除不了了,急!
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
MaterialDG.Refresh
Select Case Button.Key
Case "First"
CheckRecordCount

MaterialAdo.Recordset.MoveFirst
Case "Previous"
CheckRecordCount
MaterialAdo.Recordset.MovePrevious
If MaterialAdo.Recordset.BOF Then
MaterialAdo.Recordset.MoveFirst

End If
Case "Next"
If MaterialAdo.Recordset.RecordCount = 0 Then

Exit Sub
End If
MaterialAdo.Recordset.MoveNext
If MaterialAdo.Recordset.EOF Then
MaterialAdo.Recordset.MoveLast
End If
Case "Last"
If MaterialAdo.Recordset.RecordCount = 0 Then

Exit Sub
End If
MaterialAdo.Recordset.MoveLast
Case "Edit"

MaterialDG.AllowUpdate = True
MaterialDG.AllowAddNew = True

Case "Add"

MaterialDG.AllowAddNew = True
'MaterialDG.AllowDelete = True
MaterialDG.AllowUpdate = True
MaterialAdo.Recordset.MoveNext
If MaterialAdo.Recordset.EOF Then
MaterialAdo.Recordset.MoveLast
End If
Case "Delete"

MaterialDG.AllowDelete = True
MaterialDG.AllowUpdate = True
'MaterialDG.Move (MaterialDG.Bookmark)
If MaterialAdo.Recordset.RecordCount = 0 Then
Exit Sub
End If
If MaterialAdo.Recordset.EOF And MaterialAdo.Recordset.RecordCount = 1 Then
MaterialAdo.Recordset.Delete
MaterialAdo.Refresh
MaterialDG.Refresh
MaterialAdo.Recordset.Update
Exit Sub
ElseIf MaterialAdo.Recordset.EOF Then
MaterialAdo.Recordset.Delete
MaterialAdo.Recordset.MovePrevious
MaterialAdo.Recordset.Requery
MaterialAdo.Refresh
MaterialAdo.Recordset.Update
End If


' Else
' MsgBox "没有当前纪录"
' End If


' If MaterialAdo.Recordset.RecordCount > 1 Then
' MaterialAdo.Recordset.MoveFirst
' End If
Case "Quit"
Unload Me
'Case Else

End Select
'MaterialAdo.Recordset.Update
End Sub
sdgqx 2003-08-20
  • 打赏
  • 举报
回复
想问一下
我使用一recordset作为datagrid的数据源
当我点击一条记录时
我调用recordset的delete是不是就可以把它删除?
qingming81 2003-08-20
  • 打赏
  • 举报
回复
"行句柄引用了一个已被删除的行或被标识为删除的行”,这个是ADO及datagrid的问题:在MaterislAdo_willmove中写代码:on error resume next,看能否避免。
ywxbutterfly 2003-08-20
  • 打赏
  • 举报
回复
谢谢 iiboy,用你的方法又可以删除了,但是出现了老的问题,那就是虽然可以删除,但如果删除时不是选中整行,而是让光标停在某行的某个单元格内时点击删除,这个时候就会出现错误提示:“行句柄引用了一个已被删除的行或被标识为删除的行”,能否解决,万分感谢!
iiboy 2003-08-20
  • 打赏
  • 举报
回复
Case "Delete"
   If MaterialAdo.Recordset.EOF And MaterialAdo.Recordset.Bof then exit
   Materislado.Recordset.Delete
   MaterislAdo.Recordset.MoveNext
   if MaterislAdo.Recordset.Eof then MaterislAdo.Recordset.MoveLast
   'MaterislAdo.Refresh

1,216

社区成员

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

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