我编译都没错,运行出现了这个错误:
实时错误91,对象变量或者With块变量未设置!代码如下:
Public gStrConn As String
Public gAdoConn As ADODB.Connection
Private Sub Command1_Click()
Dim adoset As ADODB.Recordset
Dim strSQL As String
Set gAdoConn = New ADODB.Connection
gStrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\db.mdb;Persist Security Info=False"
gAdoConn.Open gStrConnstrSQL = "SELECT 用户名,密码 FROM User"Set adoset.ActiveConnection = gAdoConnadoset.CursorType = adOpenStaticadoset.Open strSQLIf (adoset.EOF = True And adoset.BOF = True) Then
MsgBox "无此用户", , "登陆"
Else
If (adoset.Fields("密码").Value = Text2.Text) Then
Form1.Show
Else
MsgBox "密码错误,请重试!", , "登陆"
End If
End If
adoset.Close
End Sub
实时错误91,对象变量或者With块变量未设置!代码如下:
Public gStrConn As String
Public gAdoConn As ADODB.Connection
Private Sub Command1_Click()
Dim adoset As ADODB.Recordset
Dim strSQL As String
Set gAdoConn = New ADODB.Connection
gStrConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\db.mdb;Persist Security Info=False"
gAdoConn.Open gStrConnstrSQL = "SELECT 用户名,密码 FROM User"Set adoset.ActiveConnection = gAdoConnadoset.CursorType = adOpenStaticadoset.Open strSQLIf (adoset.EOF = True And adoset.BOF = True) Then
MsgBox "无此用户", , "登陆"
Else
If (adoset.Fields("密码").Value = Text2.Text) Then
Form1.Show
Else
MsgBox "密码错误,请重试!", , "登陆"
End If
End If
adoset.Close
End Sub
Set adoset.ActiveConnection = gAdoConn
...
建议楼主不要将数据库关键字作为表名与字段名使用,user为关键字
另外,StrConn.Close
Public gStrConn$
Public gAdoConn As New ADODB.Connection Private Sub Command1_Click()
Dim strSQL$,adoset As New ADODB.Recordset gStrConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db.mdb;Persist Security Info=False"
gAdoConn.Open gStrConn
if gAdoConn.state=0 then
msgbox "数据库连接错误!请检查连接字符串.",48,"连库错误"
exit sub
end if strSQL="SELECT 用户名,密码 FROM [User]"
adoset.Open strSQL,gAdoConn,1,1
If adoset.EOF And adoset.BOF Then
MsgBox "无此用户",64,"登陆"
Else
If adoset(1)=Text2 Then
Form1.Show
Else
MsgBox "密码错误,请重试!",48,"登陆"
EndIf
End If
adoset.Close
set adoset=nothing
gAdoConn.close
set gAdoConn=nothing
End Sub