想用vb做个系统登陆界面,用的是sql数据库
字段设置为char
然后在vb中设置了两个文本框text用来输入用户名和密码,但是在做比较的时候为什么老是说不等呢??
大概代码如下:
Private Sub Command1_Click() Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
cn.ConnectionString = "DSN=library;UID=;PWD=;"
'cn.ConnectionTimeout = 30
cn.Open
Set rs = New Recordset
 rs.Open "select   *   from   user_manager", cnIf text1.Text = "" Then
        MsgBox "请填写用户名!", vbOKOnly + vbInformation, "注意"
        text1.SetFocus
        Exit Sub
    ElseIf text2.Text = "" Then
        MsgBox "请填写密码!", vbOKOnly + vbInformation, "注意"
        text2.SetFocus
        Exit Sub
    End Ifmingzi = rs("username")
mima = rs("pwd")If (text1.Text <> mingzi) ThenPrint "用户名不对"
Else
Print "用户名正确"End If
End Sub

解决方案 »

  1.   

    chr数据类型后面是有空格的,在比较前应该去掉空格
    If (text1.Text <> trim(mingzi)) Then
      

  2.   

    rs.Open "select   *   from   user_manager", cn你的sql语句没有指明查询的是那个用户的用户名和密码,改成
    rs.Open "select * from user_manager where username='" & text1.text & "'", cn
      

  3.   

    判断的时候
    直接判断rs是否为eof就可以了
    if rs.eof then
    Print "用户名不对"
    Else
    Print "用户名正确"
    End If
      

  4.   

    "select   *   from   user_manager", 没查用户名和密码"select * from user_manager where username='" & text1.text & "' and pwd='" text2.text "'"然后看到有没有纪录
    if rs.recordcound>0 then
      msgbox "Bingo"
    else
      msgbox "Sorry!"
    end if
      

  5.   

    要么就用查询条件写死了:
    "select * from user_manager where username='" & text1.text & "' and pwd='" text2.text "'"
    另外在查询时,判断一下记录集是否到达底部
    最后理清一下程序的行走。
      

  6.   

    "select   *   from   user_manager", 没查用户名和密码"select * from user_manager where username='" & text1.text & "' and pwd='" text2.text "'"然后看到有没有纪录
    if rs.recordcound>0 then
      msgbox "Bingo"
    else
      msgbox "Sorry!"
    end if====================
    不好,易受到注入攻击。