vb和sql的问题啊?

myppfly 2006-12-16 08:49:39
想用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", cn



If text1.Text = "" Then
MsgBox "请填写用户名!", vbOKOnly + vbInformation, "注意"
text1.SetFocus
Exit Sub
ElseIf text2.Text = "" Then
MsgBox "请填写密码!", vbOKOnly + vbInformation, "注意"
text2.SetFocus
Exit Sub
End If

mingzi = rs("username")
mima = rs("pwd")

If (text1.Text <> mingzi) Then

Print "用户名不对"
Else
Print "用户名正确"

End If




End Sub
...全文
179 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lsftest 2006-12-17
  • 打赏
  • 举报
回复
"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

====================
不好,易受到注入攻击。
guyehanxinlei 2006-12-17
  • 打赏
  • 举报
回复
要么就用查询条件写死了:
"select * from user_manager where username='" & text1.text & "' and pwd='" text2.text "'"
另外在查询时,判断一下记录集是否到达底部
最后理清一下程序的行走。
clear_zero 2006-12-16
  • 打赏
  • 举报
回复
"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
zq972 2006-12-16
  • 打赏
  • 举报
回复
判断的时候
直接判断rs是否为eof就可以了
if rs.eof then
Print "用户名不对"
Else
Print "用户名正确"
End If
zq972 2006-12-16
  • 打赏
  • 举报
回复
rs.Open "select * from user_manager", cn

你的sql语句没有指明查询的是那个用户的用户名和密码,改成
rs.Open "select * from user_manager where username='" & text1.text & "'", cn
hwcqboy 2006-12-16
  • 打赏
  • 举报
回复
chr数据类型后面是有空格的,在比较前应该去掉空格
If (text1.Text <> trim(mingzi)) Then

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧