回复 10# 的帖子
用户名没有重复的哦``有两条不同的记录,而且两条都可以登陆成功,就是在我不输入帐号点登陆的时候就出错误提示
给你个用户登陆的例子看吧
Private Sub cmdLogin_Click()
Dim j As Integer
If frmLoginFlag = True Then
SQL = "select * from Account"
Set rsnew = TransactSQL(SQL)
If rsnew.RecordCount <> 0 Then
rsnew.MoveFirst
For j = 1 To rsnew.RecordCount
If UCase(rsnew.Fields("用户名")) = UCase(txtUser.Text) And rsnew.Fields("密码") = txtPassword.Text Then
'// 登陆ok 做需要的处理
frmLogin.Hide
LoginUser = rsnew.Fields("用户名")
frmMain.StatusBar1.Panels(1).Text = frmMain.StatusBar1.Panels(1).Text & LoginUser
'//处理完毕
MsDelayTick 500
rsnew.Close
frmMain.Show
frmMain.SetFocus
Unload frmLogin
Exit Sub
Else
If rsnew.EOF = False Then
rsnew.MoveNext
Else
Exit For
End If
End If
Next j
If rsnew.EOF = True Then
logintime = logintime + 1
txtPassword = ""
txtUser = ""
If logintime >= 3 Then
logintime = 0
Me.Hide
rsnew.Close
Unload Me
Exit Sub
End If
MsgBox "密码错误或用户名不存在!!请确认后重新登录"
txtUser.SetFocus
End If
Else
MsgBox "用户数据为空, " & "!"
rsnew.Close
Me.Hide
Unload Me
End If
End If
End Sub
Public Function TransactSQL(ByVal SQL As String) As ADODB.Recordset
Dim con As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strConnection As String
Dim strArray() As String
Set con = New ADODB.Connection '
Set rs = New ADODB.Recordset '
On Error GoTo TransactSQL_Error
strConnection = "Provider=Microsoft.jet.oledb.4.0;Data Source=" & App.Path & "\data.mdb;Jet OLEDB:Database password=" & DBPWDstr
strArray = Split(SQL)
con.Open strConnection '
If StrComp(UCase$(strArray(0)), "select", vbTextCompare) = 0 Then
rs.Open Trim$(SQL), con, adOpenKeyset, adLockOptimistic
Set TransactSQL = rs '??
iflag = 1
Else
con.Execute SQL '
iflag = 1
End If
TransactSQL_Exit:
Set rs = Nothing
Set con = Nothing
Exit Function
TransactSQL_Error:
MsgBox "错误提示:" & Err.Description
iflag = 2
Resume TransactSQL_Exit
End Function
[[it] 本帖最后由 simpson 于 2008-4-16 16:09 编辑 [/it]]