车霖的ollie几立:vb制作的登陆界面,使用ACCESS数据,有一句出错!(急)

来源:百度文库 编辑:中科新闻网 时间:2024/04/27 23:58:44
Dim rs As New ADODB.Recordset
Dim cnn As New ADODB.Connection

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdOK_Click()
Dim strsql As String
Set rs = Nothing
Set cnn = Nothing
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\97版数据库.mdb;Persist Security Info=False"
cnn.Open

If txtUserName.Text = "" Then
MsgBox "请输入用户名!", vbCritical + vbOKOnly, "提示"
txtUserName.SetFocus
End If
strsql = "select * from 系统用户表 where username='" & Trim(txtUserName.Text) & "'"
rs.CursorLocation = adUseClient
'下面这行就是出错行出错提示:至少一个参数未指定值
rs.Open strsql, cnn, adOpenStatic, adLockOptimistic
If txtPassword.Text = rs.Fields("password") Then
frmMain.Show
Unload Me
Else
MsgBox ("用户名或者密码不正确!"), vbCritical + vbOKOnly, "提示"
End If
End Sub
我不懂那行的意思!

006-06-21 22:21:55

回答:bryant1976
大师
6月23日 09:18 Set cnn = Nothing 这句不正确,应该是在断开连接后才调用这句的,你却在连接之前调用,当然就会出错了。把这一句删除就好了。