这是我写的一个用户登陆验证的主要部分!
可是数据库里没有这个用户也能登陆。哪位大哥给我改一下。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
可是数据库里没有这个用户也能登陆。哪位大哥给我改一下。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
MsgBox "没有此用户", vbOKOnly, "验证"
exit sub
Else
unload me
end if
所以需要使用一个判断,使用楼上的,或者使用if rst.recordcount.eof then
……
……endif
也可以
MsgBox "没有此用户", vbOKOnly, "验证"
End '增加这一句
Else
unload me
end if
if ……
……
end if
MsgBox "没有此用户", vbOKOnly, "验证"
exit sub
Else
unload me
end if
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窗体啊!为什么啊?