注册 登录
编程论坛 VB6论坛

VB+ACCESS 做的登入器怎么老出错~请大神帮帮忙~!!

admin73896 发布于 2014-05-13 17:50, 871 次点击
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
9 回复
#2
lowxiong2014-05-13 19:01
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”就会绕过用户名的判断,认为有这个用户存在的。
#3
admin738962014-05-14 09:40
回复 2 楼 lowxiong
rs.Open sql, conn, adOpenStatic, adLockOptimistic, 1   但是老是这条这不对 说数据库引擎找不到表或查询‘table'确定他是否存在
#4
lowxiong2014-05-14 09:45
你有没有看我在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
#5
admin738962014-05-14 09:58
回复 4 楼 lowxiong
我加了~~但是还是出现错误~~~读不到数据库    我用的是VB6.0和Access2003  在引用-部件里我用的是Mictosoft ActiveX Data 2.6 Library和Mictosoft DAO 3.6 Object Library














o
#6
lowxiong2014-05-14 10:08
不需要引用dao,我是引用的microsoft active data objects 2.8 library,我刚改成2.6也通过了,你手工打开下你的数据库,确定table表,要不拷贝我的数据库放到D:\下试验就知道了,table表里的记录是:uesrname  aaa,password  123
只有本站会员才能查看附件,请 登录




[ 本帖最后由 lowxiong 于 2014-5-14 10:14 编辑 ]
#7
admin738962014-05-14 10:35
回复 6 楼 lowxiong
谢谢可以了`~
#8
admin738962014-05-14 11:35
回复 4 楼 lowxiong
还想请教你一个问题~~就是我做的这个程序~可以把QQ程序添加到设为内置不~~
#9
andy12342015-01-06 20:17
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
#10
andy12342015-01-06 20:19
不用ADO控件,只用了代码,但是要引用ADO。自已令会吧!
1