刚学习vb,做的一个登陆,总报91错误,请高手帮忙一下
Private Sub Form_Load()CenterForm Me
Dim strSQl As String
strSQl = "select * from user"
Set conn = New ADODB.Connection
Set sr = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Desktop\MyFirstVB\db1.mdb;Persist Security Info=False"
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "username can't be null,please enter your name again!", vbOKOnly + vbInformation, "alert"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "password can't be null,please enter your name again!", vbOKOnly + vbInformation, "alert"
Text2.SetFocus
Exit Sub
End If
strSQl = "select * from Users where name='" & Trim$(Text1.Text) & "' and pwd='" & Trim$(Text2.Text) & "' "
rs.CursorLocation = adUseClient
rs.Open strSQl, conn, adOpenStatic, adLockReadOnly
With rs
If .State = adStateOpen Then .Close
.Open strSQl
If .EOF Then
Try_times = Try_times + 1
If Try_times >= 3 Then
MsgBox "you alreadly tride three times,none successful,system will auto to close", vbOKOnly + vbCritical, "alert"
Unload Me
Else
MsgBox "the user was unexist or your name and password was wrong", vbOKOnly + vbQuestion, "alert"
Text1.SetFocus
Text1.Text = ""
Text1.Text = ""
End If
Else
Unload Me
Form2.Show
End If
End With
End Sub --------------------编程问答-------------------- 提示错误为:
实时错误‘91’:
对象变量或With块变量未设置。
错误行在:rs.CursorLocation = adUseClient --------------------编程问答-------------------- 你的 adUseClient 是什么东东?自始至终没见到过这个变量的定义,不定义变量就使用,当然出问题
而且你这貌似不是.NET代码 --------------------编程问答-------------------- 这个是vb的代码,不是vb.net,那个我也不知道是什么,看见别人都这样写,我也就跟着写的 --------------------编程问答-------------------- 你上面定义的是
Set sr = New ADODB.Recordset
,但是你后面又用
rs.CursorLocation = adUseClient
,一般Recordset变量用rs,你上面代码抄错了
另外,如果你是新学,那还是直接用vb.net吧,现在再去学vb不太值 --------------------编程问答-------------------- Private Sub Form_Load()
CenterForm Me
Dim strSQl As String
strSQl = "select * from user"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Administrator\Desktop\MyFirstVB\db1.mdb;Persist Security Info=False"
'rs.Open strSQl, conn, 1, 2
End Sub
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "username can't be null,please enter your name again!", vbOKOnly + vbInformation, "alert"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "password can't be null,please enter your name again!", vbOKOnly + vbInformation, "alert"
Text2.SetFocus
Exit Sub
End If
'Dim strSQl As String
strSQl = "select * from userss where myname='" & Trim$(Text1.Text) & "' and mypwd='" & Trim$(Text2.Text) & "' "
conn.CursorLocation = adUseClient
rs.Open strSQl, conn, adOpenStatic, adLockReadOnly
With rs
If .State = adStateOpen Then .Close
.Open strSQl
If .EOF Then
Try_times = Try_times + 1
If Try_times >= 3 Then
MsgBox "you alreadly tride three times,none successful,system will auto to close", vbOKOnly + vbCritical, "alert"
Unload Me
Else
MsgBox "the user was unexist or your name and password was wrong", vbOKOnly + vbQuestion, "alert"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End If
Else
'Unload Me
Form2.Show
End If
End With
End Sub
做了修改,出现3075错误,提示错误在rs.Open strSQl, conn, adOpenStatic, adLockReadOnly,想在登录框输入不空的情况下,取数值做比较登录,不知道怎么写,看看我的代码怎么改等实现成功就登录到Form2,给我点提示 --------------------编程问答-------------------- 看一下strsql是什么?表名字段名对不对,userss确定不是users?
还有,你这种写法很容易被sql注入的,还是建议你放弃vb6的学习,赶紧学.net --------------------编程问答-------------------- strSQL是一个查询语句,表面和字段都对的
--------------------编程问答-------------------- 确定load里里面的
'rs.Open strSQl, conn, 1, 2
是已经注释掉的?3075错误不是3705?
先别肯定表面和字段都对的,得到strsql后直接在mdb文件里测试 --------------------编程问答--------------------
+1
补充:.NET技术 , VB.NET