用户登录表单vb6错误



hi,我用vb6编写程序并依赖msaccess数据库我在ms访问中创建表(用户)然后我制作模块:-

Public DB As New ADODB.Connection
Public RS As New ADODB.Recordset
Public RSS As New ADODB.Recordset
Public SQLS As String
Public UserNames As String
Public UserPassword As String
Sub POOLCONNECTION()
    If DB.State = adStateOpen Then DB.Close
    DB.Provider = "Microsoft.JET.OLEDB.4.0"
    DB.Open App.Path & "data.mdb"
End Sub

和我为用户制作了一些表格:-1-我第一次创建管理员用户来检查用户表单以使用。如果没有记录,此表单将创建管理员用户代码:-

Private Sub Form_Load()
    Text1 = " "
    Text2 = " "
    Text3 = " "
    POOLCONNECTION
    SQLS = " Select * From Users "
    If RS.State = adStateOpen Then RS.Close
    RS.Open SQLS, DB, adOpenKeyset, adLockPessimistic
    If Not RS.RecordCount = 0 Then
       FRMLOGIN.Show
       Unload Me
   End If
End Sub
Private Sub save_Click()
    If Text1 = " " Then
        MsgBox " Sorry, You Must Type Username ", vbCritical +  vbMsgBoxRight, "Error"
        Text1.SetFocus
        Exit Sub
    End If
    If Text2 = " " Then
        MsgBox " Please Type Old Password ", vbCritical + vbMsgBoxRight, "  Error "
        Text2.SetFocus
        Exit Sub
    End If
    SaveMsg = MsgBox(" åá ÊÑíÏ ÇäÔÇÁ ãÏíÑ ááäÙÇã ?", vbQuestion + vbMsgBoxRight + vbYesNo, " Êã ÇáÍÝÙ  ")
    If SaveMsg = vbYes Then
        RS.AddNew
        RS![UserName] = Text1
        RS![Password] = Text2
        RS![GAdd] = True
        RS![GEdit] = True
        RS![GPrint] = True
        RS![GCreateUser] = True
        RS![GDelete] = True
        RS.Update
        MsgBox " Êã ÍÝÙ ÇáÈíÇäÇÊ", vbInformation + vbMsgBoxRight, " Saved "
        ' Save This Informations
        UserNames = Text1
        UserPassword = Text2
        ' Long Main
        Set RS = Nothing
        Set DB = Nothing
        MDIForm1.Show
        Unload Me
    End If
End Sub

在我制作了一个mn用户登录表单并尝试使用管理员用户登录后第二次使用。。eof没有读取记录登录代码:

Private Sub Command1_Click()
    If Text1 = "" Or Text2 = "" Then
        MsgBox " ÚÝæÇ íÌÈ ßÊÇÈÉ ÇÓã ÇáãÓÊÎÏã æßáãÉ ÇáãÑæÑ ", vbCritical +  vbMsgBoxRight, " ÎØà Ýì ÇáÏÎæá"
        Exit Sub
    End If
    SQLS = "Select * From Users Where Username = ' " & Text1 & " '  And  Password = ' " & Text2 & " ' "
    If RS.State = adStateOpen Then RS.Close
    RS.Open SQLS, DB, adOpenKeyset, adLockPessimistic
    If RS.EOF Then
        MsgBox " Sorry, The Username And Password Is Wrong ! ", vbCritical +          vbMsgBoxRight, " Error Login "
    Else     
        Set RS = Nothing
        Set DB = Nothing
        MDIForm1.Show
        Unload Me
    End If
End Sub
Private Sub Command2_Click()
    Unload Me
End Sub
Private Sub Form_Load()
    POOLCONNECTION
End Sub
Private Sub text1_keypress(keyAscii As Integer)
    If keyAscii = 13 Then
        Text2.SetFocus
    End If
End Sub
Private Sub text2_keypress(keyAscii As Integer)
    If keyAscii = 13 Then
        Command1.SetFocus
    End If
End Sub

删除text s:前后不必要的空格

SQLS = "Select * From Users Where Username = '" & Text1 & "'  And  Password = '" & Text2 & "' "

最新更新