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

VB与数据库连接不上···老报错是:错误91 有没有人可以帮个忙看看啊?谢啦!!!

If rst.RecordCount > 0 Then  --------------------编程问答-------------------- endif
下面的完善中间 --------------------编程问答-------------------- 你的数据库连接代码在哪儿啊~~~~ --------------------编程问答-------------------- 代码在哪里~~~~~~~~~~~~~~~~~ --------------------编程问答--------------------
引用楼主 slz1309054610 的回复:
If rst.RecordCount > 0 Then

就这一行代码,还有不报错的可能吗? --------------------编程问答-------------------- 完整的错误提示是不是这样:
实时错误91,“对象变量或with变量未设置”

搜索一下,可以找到很多的... --------------------编程问答-------------------- 代码在这边

Private Sub Form_Load()
    Dim rst As New ADODB.Recordset
    Dim SQL As String
    Dim msg As String
    Dim rights As String
    Call GetConnStr
    Conn.Open GetConnStr
    OpenConn() = True
    
    '查找权限
    SQL = "select UPower from UI where UID='" & UID & "'"
    Set rst = SelectSQL(SQL, msg)
    If rst.RecordCount > 0 Then
        rights = Trim(rst.Fields(0))
        rst.Close
        MsgBox ("没有用户信息!")
    Else
        Exit Sub
    End If
  就是报错  实时错误91,“对象变量或with变量未设置”

  弄了半天还是连不上!!! --------------------编程问答-------------------- Private Sub Form_Load()
    Dim rst As New ADODB.Recordset
    Dim SQL As String
    Dim msg As String
    Dim rights As String
     
    
    '查找权限
    SQL = "select UPower from UI where UID='" & UID & "'"
    Set rst = SelectSQL(SQL, msg)
    If rst.RecordCount > 0 Then
        rights = Trim(rst.Fields(0))
        rst.Close
        MsgBox ("没有用户信息!")
    Else
        Exit Sub
    End If


类模块的代码:
Public Function GetConnStr() As String
'得到数据库连接字符串,用户可以在此处设置连接字符串
'User ID是数据库用户ID,PassWord是登录密码
    GetConnStr = "Provider=SQLOLEDB;User ID=sa;PassWord=123;Initial Catalog=人事管理系统:Data Source=LBWIN7"
            
End Function --------------------编程问答-------------------- Set rst = SelectSQL(SQL, msg)

SelectSQL,应该也是自己写的函数吧
--------------------编程问答-------------------- Set rst = SelectSQL(SQL, msg)

SelectSQL,应该也是自己写的函数吧
补充:VB ,  基础类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,