想用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
字段设置为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
If (text1.Text <> trim(mingzi)) Then
rs.Open "select * from user_manager where username='" & text1.text & "'", cn
直接判断rs是否为eof就可以了
if rs.eof then
Print "用户名不对"
Else
Print "用户名正确"
End If
if rs.recordcound>0 then
msgbox "Bingo"
else
msgbox "Sorry!"
end if
"select * from user_manager where username='" & text1.text & "' and pwd='" text2.text "'"
另外在查询时,判断一下记录集是否到达底部
最后理清一下程序的行走。
if rs.recordcound>0 then
msgbox "Bingo"
else
msgbox "Sorry!"
end if====================
不好,易受到注入攻击。