奇怪的问题,关于sql和vb
sql数据库
cnemployee,rsemployee设置都没有问题,
比如username=123 password=456
我输入都没有问题,可是她老是执行msgbox "无效的密码,请重试!", , "登录"
这到底是为什么?怎么回事?都快被她逼疯了,到底是哪里错了
rsemployee.open "select * from usermessage where username = " & txtusername.text & "", cnemployee, adopendynamic, adlockoptimistic
dim p, q as string
p = rsemployee.fields("password")
q = txtpassword.text
print p & q 这里输出的也都是相同456
检查正确的密码
if p = q then
msgbox "come in"
me.hide
else
msgbox "无效的密码,请重试!", , "登录"
txtpassword.setfocus
end if
推荐阅读
if trim(p) = trim(q) then ‘会不会有空格?
是啊,会不会有空格?
if rsemployee.state=adstateopen then rsemployee.close
rsemployee.open "select * from usermessage where username = " & txtusername.text & "", cnemployee, adopendynamic, adlockoptimistic
if rsemployee.recordcount=0 then
msgbox "没有此用户名,请重新输入!",48,"提示"
txtusername.setfocus
eixt sub
else
if not (isnull(rs!password) or rs!password="") then 数据库中密码字段不为空
if rs!password=trim(txtpassword.text) then
msgbox "come in"
me.hide
else
msgbox "无效的密码,请重试!", , "登录"
txtpassword.setfocus
exit sub
end if
else 数据库中密码字段为空
if trim(txtpassword.text)<>"" then
msgbox "无效的密码,请重试!", , "登录"
txtpassword.setfocus
exit sub
else
msgbox "come in"
me.hide
end if
end if
end if
楼上的真是严谨
p = trim(rsemployee.fields("password"))
q = trim(txtpassword.text)
rsemployee.open "select * from usermessage where username = " & trim(txtusername.text) & "", cnemployee, adopendynamic, adlockoptimistic
会不会是两变量类型不一样。
可能是没有去掉空格的问题
全部转成数字类型来比较。
if clng(p) = clng(q) then
--
else
--
end if
是空格,我以前也碰到过
嗯。楼主试试看
.

讨论区