注册 登录
编程论坛 VB6论坛

[求助]VB登陆界面与后台SQL的连接检验

fancysea 发布于 2006-06-16 23:59, 2181 次点击
dim strSQL as String
dim cn as new adodb.connection
dim rs as new adodb.recordset
cn.connectionstring=连接字符串
cn.open
cn.CursorLocation = adUseClient
strSQL ="select 密码 from 表 where 登录名='" & txtUserID.Text & "'"
rs.open strSQL,cn,adOpenStatic, adLockReadOnly
if rs.recordcount = 0 then
msgbox "用户名不正确"
else
if rs.fields[0].value = txtPwd.text then
msgbox "登录成功"
else
msgbox "密码错误"
end if
end if

这是一段VB登陆界面与后台SQL连接检验的一段代码。可是有好多地方看不懂,请高手帮忙解释一下!谢了!
4 回复
#2
stylist2006-06-17 00:19
其实有好多的时候,你都可以看看msdn的嘛!
这段代码只是数据库编程的最基础知识!
你学会后,vb,vb.net,asp数据库编程方式都会差不多!

dim strSQL as String
dim cn as new adodb.connection
dim rs as new adodb.recordset

cn.connectionstring=连接字符串 '设置connection对象的连接字符串
cn.open
cn.CursorLocation = adUseClient ’设置connection对象的指针位置,aduseclient为客户端

strSQL ="select 密码 from 表 where 登录名='" & txtUserID.Text & "'" '使用sql语句 通过'登陆名'查询表中的'密码'字段

rs.open strSQL,cn,adOpenStatic, adLockReadOnly '使用静态浮标表,彩用只读方式执行 strsql语句
if rs.recordcount = 0 then ‘如果rs.recordcount(记录数)为’0',表示,表中没有这个字段,就是用户名错误
msgbox "用户名不正确"
else ’否则用户就存在,以下是对密码的判断
if rs.fields[0].value = txtPwd.text then
msgbox "登录成功"
else
msgbox "密码错误"
end if
end if

#3
fancysea2006-06-17 23:10

非常感谢楼上的这位朋友!谢谢!

#4
52316wsf2006-06-18 12:59

好 明白了 谢谢啦啊

#5
yyyypooi2012-12-27 20:10
回复 2楼 stylist
谢啦!
1