VB6 MS数据网格控件“;“当前行不可用”;

VB6 MS数据网格控件“;“当前行不可用”;,vb6,Vb6,我让datagrid使用adodb(不是adodc),当用户双击datagrid中的记录时,记录将出现在标签上。但当用户关闭表单时。有一个错误 Ms Datagrid控件/当前行不可用 我不知道怎么了,我已经在窗体卸载时关闭了记录集 这是我的密码 Dim myrecordset As New ADODB.Recordset Private Sub dtgrid_DblClick() Label9.Caption = "" Label9.Caption = dtgrid.Columns(0) E

我让datagrid使用adodb(不是adodc),当用户双击datagrid中的记录时,记录将出现在标签上。但当用户关闭表单时。有一个错误

Ms Datagrid控件/当前行不可用

我不知道怎么了,我已经在窗体卸载时关闭了记录集

这是我的密码

Dim myrecordset As New ADODB.Recordset

Private Sub dtgrid_DblClick()
Label9.Caption = ""
Label9.Caption = dtgrid.Columns(0)
End Sub

Private Sub Form_Load()
Call ConnectDB
With myrecordset
.ActiveConnection = con
'.LockType = adLockReadOnly
.CursorType = adOpenForwardOnly
.CursorLocation = adUseClient
.Open "SELECT * FROM Foo "
End With
Set dtgrid.DataSource = myrecordset
End Sub

Private Sub Form_Unload(Cancel As Integer)
myrecordset.close
set myrecordset = nothing
Call CloseDB
End Sub
这是从模块

Public function CloseDB
    Set CMD = Nothing 'adodb command
    con.Close
    Set con = Nothing 'adodb connection
end sub

可能是因为您关闭了记录集,而数据源仍然指向它。在关闭记录集之前,请尝试将DataSource属性设置为nothing

您能发布
CloseDB
函数的代码吗?@George谢谢,请查看我的问题。一年后,当答案正确时,有人否决了它。