vb6.0登陆界面问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 12:06:21
我用vb6.0做登陆界面,以下是登陆控件的代码:
Private Sub Command1_Click()
Dim username, userpassword, str As String
Dim ntrycount As Integer
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
username = Trim(Text1.Text)
userpassword = Trim(Text2.Text)
str = "select * from admin where 用户名='" & username & "' and 用户密码 = '" & userpassword & " '"
rs.Open str, connectstring, adOpenKeyset, 2
If rs.EOF Then
MsgBox "对不起,无此用户或者密码不正确!请重新输入!!", vbCritical, "错误"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
ntrycount = ntrycount + 1
If ntrycount >= 3 Then
MsgBox "您无权操作本系统!", vbCritical, "无权限"
Unload Me
End If
Else
Form2.Show
Unload Me
End If
End Sub

可connectString这里不能通过,VB6.0显示没有定义参数。是哪里出错了??
如何赋值connectstring??

Option Explicit
Dim cnt As Integer

Private Sub Command1_Click()
Dim sql As String
Dim rs_login As New ADODB.Recordset
Dim conn As New ADODB.Connection
conn.Open "provider=Microsoft.Jet.OLEDB.4.0; data source=" & App.Path & "\db1.mdb"
'app.path是一个相对路径需要把程序和数据库放到同一根目录中 上面的意思是连接数据库microsoft-4.0:需要用到工程引用Microsoft a****x- 2.5这里不写全了你可以看下

If Trim(Text1.Text) = "" Then
MsgBox "用户名不能为空,请重新输入!"
Text1.SetFocus
Else
sql = "select * from 用户权限 where 用户名称='" & Trim(Text1.Text) & "'"
rs_login.Open sql, conn, adOpenKeyset, adLockPessimistic
If rs_login.EOF = True Then
MsgBox "没有这个用户,请重输入!", vbOKOnly + vbExclamation, ""
Text1.Text = ""
Text1.SetFocus '将游标放到text1中
Else
username = Text1.Text
If Trim(rs_login.Fields(1)) = Trim(Text2.Text) T