当前位置:编程学习 > VB >>

大家好,这是我在VB编程ADO访问数据是遇到的问题!

Private Sub Command1_Click()
If Text1.Text = "" Then
   MsgBox "您还没有注册", , "系统提示"
   MDIForm1.Show
   Unload Me
   Exit Sub
End If
    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.xdb.Enabled = False
MDIForm1.xda.Enabled = False
MDIForm1.xfc.Enabled = False
End Select
MDIForm1.Show
adors.Close
Unload Me
End If

End Sub

运行之后出现了问题,“实时错误3704,对象关闭时不允许操作”其中:“Set adors = adocon.Execute("select * from 用户表 where 用户姓名=ltrim('" & Text1 & "') and 密码=ltrim('" & Text2 & "') and 用户类型=ltrim('" & Combo1.Text & "')")被提示为出错误的地方”
清高手给释疑谢谢了! --------------------编程问答-------------------- 那是你在其他地方关闭了连接对象的缘故。 --------------------编程问答-------------------- 或者你还没有打开连接对象。 --------------------编程问答-------------------- 在执行
Set adors = adocon.Execute("select * from 用户表 where 用户姓名=ltrim('" & Text1 & "') 
之前,要确定adocon对象已经调用了Open方法

并adors必须也定义成对象.

如:
dim adors as new adodb.recordset

adocon.open  '调用此句之前必须为adocon设置相应的属性

Set adors = adocon.Execute("select * from 用户表 where 用户姓名=ltrim('" & Text1 & "') 
--------------------编程问答-------------------- 楼上的哥哥,我已经在模块中声明了,我的代码是这样的:“Public adoCon As New ADODB.Connection
Public adors As New ADODB.Recordset
Public Sub main()
    Set adoCon = New ADODB.Connection
    adoCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\clgl.mdb" & ";Persist Security Info=False"
    frmLogin.Show
    frmLogin.Text1.SetFocus
End Sub”但是还是原来的毛病!
--------------------编程问答-------------------- adoCon 是局部变量还是全局变量?? --------------------编程问答-------------------- 直接使用记录集打开的方法试一试。 --------------------编程问答-------------------- 看错了,呵呵
 Set adors = adocon.Execute("select * from 用户表 where 用户姓名=ltrim('" & Text1 & "') and 密码=ltrim('" & Text2 & "') and 用户类型=ltrim('" & Combo1.Text & "')")
语句有问题!!
 dim SQL as string
SQL  = "select * from 用户表"
SQL  = SQL & " where 用户姓名= '" & ltrim( Text1 ) & "'"
SQL  = SQL & " AND 密码= '" & ltrim( Text2 ) & "'"
SQL  = SQL & " AND 用户类型= '" & ltrim( Combo1.Text) & "'"

 Set adors = adocon.Execute(SQL)
--------------------编程问答-------------------- adocon.Execute("select * from 用户表 where 用户姓名=ltrim('" & Text1 & "') and 密码=ltrim('" & Text2 & "') and 用户类型=ltrim('" & Combo1.Text & "')")

检查下这个语句是不是没有读取到数据????
--------------------编程问答-------------------- 如果你定义一个Recordset对象,我想就简单的多了
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,