这是我写的一个用户登陆验证的主要部分!
可是数据库里没有这个用户也能登陆。哪位大哥给我改一下。set conn = New ADODB.Connection
Set rst = New ADODB.Recordsetconn.ConnectionString = "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=manageer;Data Source=JACK"
conn.Open
tetsql = "select * from pass where 用户名='" & Trim$(Text1.Text) & "'" & "And 密码='" & Trim(Text2.Text) & "'"
tetsql = Trim$(tetsql)Set rst.ActiveConnection = conn
rst.Open tetsqlIf rst.RecordCount = 0 Then
       MsgBox "没有此用户", vbOKOnly, "验证"
Else
  unload me
end if

解决方案 »

  1.   

    If rst.RecordCount = 0 Then
           MsgBox "没有此用户", vbOKOnly, "验证"
           exit sub
    Else
      unload me
    end if
      

  2.   

    楼主只打开了数据库,但是没有判断返回的结果是否为0,就成了,只要能访问数据库就能登陆了!
    所以需要使用一个判断,使用楼上的,或者使用if rst.recordcount.eof then
    ……
    ……endif
    也可以
      

  3.   

    If rst.RecordCount = 0 Then
           MsgBox "没有此用户", vbOKOnly, "验证"
           End                                  '增加这一句
    Else
      unload me
    end if
      

  4.   

    判断我不是有吗?
    if ……
    ……
    end if
      

  5.   

    但是你判断完了就继续了,需要 exit sub 啊!
      

  6.   

    可是我输入一个数据库没有的记录,它连消息框也不弹出,就直接unload了。
      

  7.   

    真是急死人!我单步调试,他在if.... else里不管怎样,就往else里走.
      

  8.   

    If (rst.RecordCount = 0) Then
           MsgBox "没有此用户", vbOKOnly, "验证"
           exit sub
    Else
      unload me
    end if
      

  9.   

    整个程序是这样的!Private Sub Command1_Click()
    Set conn = New ADODB.Connection
    Set rst = New ADODB.Recordsetconn.ConnectionString = "Provider=SQLOLEDB.1;Password=123;Persist Security Info=True;User ID=sa;Initial Catalog=manageer;Data Source=JACK"
    conn.Open
    tetsql = "select * from pass where 用户名='" & Trim$(Text1.Text) & "'" & "And 密码='" & Trim(Text2.Text) & "'"
    tetsql = Trim$(tetsql)Set rst.ActiveConnection = conn
    rst.CursorLocation = adUseServer
    rst.LockType = adLockOptimistic
    rst.CursorType = adOpenKeyset
    rst.Open tetsql
    If rst.RecordCount = 0 Then
           MsgBox "没有此用户", vbOKOnly, "验证"
           
    Else
           Unload Me
    End IfEnd Sub可是不管输入什么,都是unload窗体啊!为什么啊?