可能是我的问题太长了,实际上是这样的
我用记录集取数据的时候,把SQL语句当做字符发送到记录集的source对象执行
在测试的时候,数据库连接成功,但是执行到这条语句的时候
Set userRst = GetSql(strQuery)
'向getsql函数发送一条sql语句,strquery为SQL语句,然后赋给记录集useRst
If userRst.RecordCount = 1 Then
If txtPassWord.Text = userRst.Fields("userpassword") Then
Load MDIfrmMain
MDIfrmMain.Show
Unload Me
Else
MsgBox "密码错误"
Exit Sub
End If
就是if语句的时候,提示"实时错误‘3704’,对象关闭时,不允许操作"
很郁闷,数据库连接是成功的,请问这是什么原因。万分感谢!!!!!
我用记录集取数据的时候,把SQL语句当做字符发送到记录集的source对象执行
在测试的时候,数据库连接成功,但是执行到这条语句的时候
Set userRst = GetSql(strQuery)
'向getsql函数发送一条sql语句,strquery为SQL语句,然后赋给记录集useRst
If userRst.RecordCount = 1 Then
If txtPassWord.Text = userRst.Fields("userpassword") Then
Load MDIfrmMain
MDIfrmMain.Show
Unload Me
Else
MsgBox "密码错误"
Exit Sub
End If
就是if语句的时候,提示"实时错误‘3704’,对象关闭时,不允许操作"
很郁闷,数据库连接是成功的,请问这是什么原因。万分感谢!!!!!
Public Function GetSql(ByVal strSql As String) As ADODB.Recordset
On Error GoTo linkerr
Dim Rst As New ADODB.Recordset
Rst.Source = strSql
Rst.ActiveConnection = Con
Rst.CursorType = adOpenKeyset
Rst.LockType = adLockOptimistic
Rst.Open
Set Rst = GetSql
Exit Function
linkerr:
MsgBox "错误代码:" & Err.Number & "错误描述:" & Err.Description, vbCritical + vbOKOnly, "错误提示"
End Function
On Error GoTo linkerr
Set Con = New ADODB.Connection
Con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\data\milk.mdb;Persist Security Info=False"
Con.CursorLocation = adUseClient
Con.CommandTimeout = 15
Con.Open
Link = True
Exit Function
linkerr:
Link = False
MsgBox "数据连接错误"
End Function
Public Sub main()
If Link = True Then
MsgBox "数据库连接成功"
Load frmLogin
frmLogin.Show
Else
MsgBox "数据库连接失败"
End If
End Sub
不知这样可否
MsgBxo userRst.State
If userRst.RecordCount = 1 Then
....
Set Getsql=Rst