来帮我看看下面这个VB登陆代码!!!

来源:百度知道 编辑:UC知道 时间:2024/06/03 18:29:00
Private Sub Command1_Click()
If id.Text = "" Then
MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "友情提示"
id.SetFocus
Exit Sub
End If
If password.Text = "" Then
MsgBox "密码不能为空!", vbOKOnly + vbInformation, "友情提示"
password.SetFocus
Exit Sub
End If

Dim strSQl As String
strSQl = "select * from Users where users_name='" & Trim$(id.Text) & "' and password='" & Trim$(password.Text) & "' "

Dim str As New ADODB.Recordset
Set str = New ADODB.Recordset
str.CursorLocation = adUseClient
str.Open strSQl, conn, adOpenStatic, adLockReadOnly

With str
If .State = adStateOpen Then .Close
.Open strSQl
If .EOF Then
Try_times = Try_times + 1

貌似这个 conn 还没看见在那定义及连接数据库,当然出错了!!!

而且还有这个也是不正确的:
Dim str As New ADODB.Recordset
Set str = New ADODB.Recordset

....

已经是 New 了一次了,为何还要 New 多次,内存多也不必这样啊!!!