首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用户登录表单vb6错误

用户登录表单vb6错误
EN

Stack Overflow用户
提问于 2015-04-08 12:23:08
回答 1查看 137关注 0票数 0

嗨,我用vb6编写程序,依赖ms access数据库,我在ms access (用户)中创建表,然后生成模块:-

代码语言:javascript
复制
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-我做了检查用户表单来创建管理员用户,这是我第一次使用。如果没有记录,此表单将创建管理用户代码:-

代码语言:javascript
复制
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

第二次使用后,我做了admin用户登录表单显示,我试图与管理用户登录。eof没有读取记录登录代码:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-09 12:18:04

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

代码语言:javascript
复制
SQLS = "Select * From Users Where Username = '" & Text1 & "'  And  Password = '" & Text2 & "' "
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29514513

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档