标题:VB+ACCESS 做的登入器怎么老出错~请大神帮帮忙~!!
只看楼主
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
结帖率:81.82%
 问题点数:0 回复次数:9 
VB+ACCESS 做的登入器怎么老出错~请大神帮帮忙~!!
Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim connstr As String
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db1.mdb;Persist Security Info=False"
ql = "select * from table where uesrname='" & Text1.Text & "'"
conn.CursorLocation = adUseClient
conn.connectionstring = connstr
conn.Open
rs.Open sql, conn, adOpenStatic, adLockOptimistic, 1
'Set rs = conn.Execute(sql)
'rs.Open sql, conn, adOpenStatic, adLockOptimistic
If rs.RecordCount = 0 Then
MsgBox "用户不存在"
rs.Close
conn.Close
Exit Sub
End If
If Text2.Text <> rs("password") Then
MsgBox "密码错误"
rs.Close
conn.Close
Else
rs.Close
conn.Close
from2.Show
Unload Me
End If
      
End Sub

Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim connectionstring As String
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "D:\glxt.mdb;Persist Security Info=False"

End Sub
搜索更多相关主题的帖子: False where 
2014-05-13 17:50
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
ql = "select * from table where uesrname='" & Text1.Text & "'"应该为sql = "select * from [table] where uesrname='" & Text1.Text & "'"
1、你并没有定义ql变量,犯极低级错误 2、table是数据库默认关键字,你要用就必须加【】区分

from2.Show估计应该是form2.show

为防止爆库,对有输入的部分一定要做字符合法性判断,过滤掉'+-%#><等符号,否则别人很轻松绕过密码判断,比如在用户名文本框输入 “1' or 1=1 or '1=1”就会绕过用户名的判断,认为有这个用户存在的。
2014-05-13 19:01
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
得分:0 
回复 2 楼 lowxiong
rs.Open sql, conn, adOpenStatic, adLockOptimistic, 1   但是老是这条这不对 说数据库引擎找不到表或查询‘table'确定他是否存在
2014-05-14 09:40
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
你有没有看我在2楼的回复?不是给你说了在sql语句里table要用中括号?你拷贝下面的代码吧,我运行的是正常的

Private Sub Command1_Click()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim connstr As String
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\db1.mdb;Persist Security Info=False"
sql = "select * from [table] where uesrname='" & Text1.Text & "'"
conn.CursorLocation = adUseClient
conn.connectionstring = connstr
conn.Open
rs.Open sql, conn, adOpenStatic, adLockOptimistic, 1
'Set rs = conn.Execute(sql)
'rs.Open sql, conn, adOpenStatic, adLockOptimistic
If rs.RecordCount = 0 Then
MsgBox "用户不存在"
rs.Close
conn.Close
Exit Sub
End If
If Text2.Text <> rs("password") Then
MsgBox "密码错误"
rs.Close
conn.Close
Else
rs.Close
conn.Close
form2.Show
Unload Me
End If
      
End Sub

Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim connectionstring As String
connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "D:\glxt.mdb;Persist Security Info=False"

End Sub
2014-05-14 09:45
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
得分:0 
回复 4 楼 lowxiong
我加了~~但是还是出现错误~~~读不到数据库    我用的是VB6.0和Access2003  在引用-部件里我用的是Mictosoft ActiveX Data 2.6 Library和Mictosoft DAO 3.6 Object Library














o
2014-05-14 09:58
lowxiong
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:27
帖 子:652
专家分:3402
注 册:2008-5-7
得分:0 
不需要引用dao,我是引用的microsoft active data objects 2.8 library,我刚改成2.6也通过了,你手工打开下你的数据库,确定table表,要不拷贝我的数据库放到D:\下试验就知道了,table表里的记录是:uesrname  aaa,password  123
Db1.zip (11.48 KB)




[ 本帖最后由 lowxiong 于 2014-5-14 10:14 编辑 ]
2014-05-14 10:08
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
得分:0 
回复 6 楼 lowxiong
谢谢可以了`~
2014-05-14 10:35
admin73896
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2014-5-9
得分:0 
回复 4 楼 lowxiong
还想请教你一个问题~~就是我做的这个程序~可以把QQ程序添加到设为内置不~~
2014-05-14 11:35
andy1234
Rank: 1
等 级:新手上路
威 望:1
帖 子:16
专家分:7
注 册:2014-6-15
得分:0 
Private DB As ADODB.Connection
Private Rs As ADODB.Recordset

Private Sub Command1_Click()
Dim i As Integer
For i = 1 To Rs.RecordCount
Rs.AbsolutePosition = i
If Trim(Rs("name")) = Text1.Text And Trim(Rs("password")) = Text2.Text Then
Form2.Show
Unload Form1
Exit For
Else
If i = Rs.RecordCount Then
MsgBox "用户与密码不正确,请重新输入", , "登录"
Command2_Click
End If

End If
Next
End Sub

Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub

Private Sub Command3_Click()
End
End Sub

Private Sub Form_Load()
Set DB = New ADODB.Connection
DB.Open "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\EMS.mdb"
Set Rs = New ADODB.Recordset
Rs.Open "info", DB, adOpenKeyset, adLockOptimistic

End Sub
2015-01-06 20:17
andy1234
Rank: 1
等 级:新手上路
威 望:1
帖 子:16
专家分:7
注 册:2014-6-15
得分:0 
不用ADO控件,只用了代码,但是要引用ADO。自已令会吧!
2015-01-06 20:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-431475-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.871106 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved