实时错误:3704怎么解决呀?

winjing 2008-05-19 04:34:09
我的登陆框源代码是这样的!

Dim i As Integer

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1.SetFocus
End If
End Sub

Private Sub Command1_Click()

Set adors = adoCon.Execute("select * from 用户表 where 用户姓名=ltrim('" & Text1 & "') and 密码=ltrim('" & Text2 & "') and 用户类型=ltrim('" & Combo1.Text & "')")
If adors.EOF Then
MsgBox "您输入的信息有误,请重新输入!", , "系统提示"
Text1 = ""
Text2 = ""
Text1.SetFocus
i = i + 1
If i = 3 Then
MsgBox "对不起,您已无权使用本系统!", , "系统提示"
Unload Me
End If
Else
Select Case adors!用户类型
Case "管理员"

Case "普通用户"
MDIForm1.mnuyydelete.Enabled = False
MDIForm1.mnusyscsh.Enabled = False
MDIForm1.mnuglyset.Enabled = False
End Select
MDIForm1.Show
adors.Close
Unload Me
End If
End Sub

Private Sub Command2_Click()
Unload Me
'adoRs.Close
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Text2.SetFocus
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Combo1.SetFocus
End If
End Sub

运行时出现了3704的错误,不知道是怎么回事!~
出错提示是这句:
Set adors = adoCon.Execute("select * from 用户表 where 用户姓名=ltrim('" & Text1 & "') and 密码=ltrim('" & Text2 & "') and 用户类型=ltrim('" & Combo1.Text & "')")
...全文
455 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Fanks 2008-05-21
  • 打赏
  • 举报
回复
adors.open("Execute里的内容",adoCon),这样在没有检索到结果的时候记录集也是打开的
winjing 2008-05-20
  • 打赏
  • 举报
回复
对于3楼的回复,要怎么改变下呢?
winjing 2008-05-20
  • 打赏
  • 举报
回复
忘记说了,我用的ACCESS.因为有较强余震的通知!就一直没上网!
cbm6666 2008-05-19
  • 打赏
  • 举报
回复
一般登录 用户类型 是没必要列入条件的.

这代码你参考看看吧, 我用的是 Find 用户的方式 来验证身份


【CBM666 的密码登录 ADODB】

'引用 Microsoft ActiveX Data Objects 2.5 Library(调用 Msado15.dll)
'添加 Text1 Text2 Command1
'在同路径app.path下放 cbm666.mdb 含cbmpass表,当然你必需改为你自己的数据库名与表名.

'**** 请注意!! 数据库:cbm666.mdb 表:cbmpass 要改为你自己的,并把它放在程序同路径下
'字段是 usernm 与 passw 与 level 都是字元型 (三个字段:用户名,密码,等级)

Option Explicit
Public conn As New ADODB.Connection '定义数据连接字符串
Public rs As New ADODB.Recordset '定义记录集
Dim i%, db$, errpass%, appdisk$, password$, levelb$
Dim finduser As Boolean

Private Sub Form_Load()
appdisk = IIf(Right(App.Path, 1) = "\", App.Path, App.Path & "\")
db = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & appdisk & "cbm666.mdb"
conn.CursorLocation = adUseClient
conn.Open db '打开数据库连接
rs.Open "cbmpass", conn, adOpenKeyset, adLockPessimistic '打开记录集
Command1.Caption = "登 录"
Text1.Text = "": Text2.Text = "": Text2.PasswordChar = "*"
End Sub

Private Sub Form_Activate()
Text1.SetFocus
End Sub

Private Sub Form_Unload(Cancel As Integer)
rs.Close: conn.Close
Set rs = Nothing: Set conn = Nothing: Set Form1 = Nothing
End
End Sub

Private Sub Command1_Click()
If SearchData(Text1.Text) Then
MsgBox "登录成功! 您的等级是:" & rs.Fields("level"), vbOKOnly, "密码登录"
Unload Me
Else
errpass = errpass + 1
If errpass >= 3 Then
MsgBox "对不起,您没有任何权限登录使用本系统", vbCritical, "密码登录"
Unload Me
Else
MsgBox "用户名或密码错误,请重新输入", vbCritical, "密码登录"
Text1.SetFocus
End If
End If
End Sub

Function SearchData(Schstr$) As Boolean
SearchData = False
rs.MoveFirst
rs.Find "usernm = " & Chr(39) & Schstr & Chr(39)
If Not rs.EOF Then SearchData = True
End Function

Fanks 2008-05-19
  • 打赏
  • 举报
回复
我记得用Set adors = adoCon.Execute(...)这种方式,如果没有检索到结果,那么adors是没有打开的,如果进行操作会报错
Fanks 2008-05-19
  • 打赏
  • 举报
回复
抱歉记错了,可以用
Fanks 2008-05-19
  • 打赏
  • 举报
回复
你用的数据库是什么啊?如果是SQL Server,它可不支持ltrim,你只能用substring了

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧