Public Sub conn1()
Dim DBpath, Connstr, conn As String
DBpath = "db.mdb"
Connstr = "Provider=Microsoft.JET.OLEDB.4.0;DATA Source=" & mServer.MapPath(DBpath)
Set conn = mServer.CreateObject("ADODB.Connection")
conn.open Connstr
End Sub说conn没有定义好
求助啊

解决方案 »

  1.   

    Set conn = Server.CreateObject("ADODB.Connection")
      

  2.   

    Option Explicit' ===========================================================' ------------ 必须的Asp对象 ----------------
    Private mContext As ScriptingContext
    Private mApplication As Application
    Private mResponse As Response
    Private mRequest As Request
    Private mSession As Session
    Private mServer As Server
    ' ------------------------------------------' 接收ScriptingContext对象
    ' 初始化各个ASP对象
    Public Sub OnStartPage(PassedScriptContext As ScriptingContext)
        
        ' Asp运行环境对象
        Set mContext = PassedScriptContext
        
        ' Asp 五大对象
        Set mApplication = mContext.Application
        Set mRequest = mContext.Request
        Set mResponse = mContext.Response
        Set mServer = mContext.Server
        Set mSession = mContext.Session
        
    End Sub' 释放内部对象
    Public Sub OnEndPage()
        Set mApplication = Nothing
        Set mRequest = Nothing
        Set mResponse = Nothing
        Set mServer = Nothing
        Set mSession = Nothing
        
        Set mContext = Nothing
    End SubPublic Sub conn1()
    Dim DBpath, Connstr, conn As String
    DBpath = "db.mdb"
    Connstr = "Provider=Microsoft.JET.OLEDB.4.0;DATA Source=" & mServer.MapPath(DBpath)
    Set conn = mServer.CreateObject("ADODB.Connection")
    conn.open Connstr
    End Sub全部代码写出来了
    帮忙看看
      

  3.   

    Application,session这些是ASP中的东西。。VB是不能直接利用的把。。需要你把值获得后传进来的把。发个以前写的BBS的DLL部分代码给你看看把。
    Option Explicit
    Public ConnString As String
    Public iPage As Integer
    Public PageSize As Integer
    Public bbsid As Integer
    Public Deep As Integer
    Public UserId As String
    Public UserName As String
    Public Groupid As Integer
    Public Title As String
    'Public Time As Date
    Public Best As Integer
    Public Faceid As Integer
    Public IsEmail As Integer
    Public BBs_content As String
    Public ArrayCount As Integer
    Public ArrayItem As Integer
    Dim Conn As New ADODB.Connection
    Public Sub DataConn()
             Conn.Open ConnString
             Conn.CommandTimeout = 300
             Conn.CursorLocation = adUseClient
    End Sub
    Public Sub DisDataConn()
            Set Conn = Nothing
    End SubPublic Function List() As Variant On Error GoTo ErrorTrap
     
     Dim Rs   As New ADODB.Recordset
     Dim Rs1   As New ADODB.Recordset
     Dim Str_Sql As String
     Dim BBS_Count As Integer
     Dim i As Integer
     Dim Size As Integer
     Dim bbs_list()
     
     Str_Sql = "Select count(*) From bbs "
     Str_Sql = Str_Sql & " Where  groupid = " & Groupid
     If Best = 1 Then
        Str_Sql = Str_Sql & " And Best = 1 "
     End If
     Set Rs1 = Conn.Execute(Str_Sql)
        
     BBS_Count = Rs1(0)
     'Rs1.Close
     Set Rs1 = Nothing
     
      
     Str_Sql = "Select bbsid,deep,userid,username,groupid,Title,time,see,best,faceid,isemail "
     Str_Sql = Str_Sql & " From bbs "
     Str_Sql = Str_Sql & " Where  groupid = " & Groupid
     If Best = 1 Then
        Str_Sql = Str_Sql & " And Best = 1 "
     End If
     Str_Sql = Str_Sql & " order by RootId + BBSid - Sign(RootId) * BBSid desc,ordernum "
     Rs.CursorLocation = adUseClient
     Rs.Open Str_Sql, Conn, 1
     Rs.PageSize = PageSize
       
     If iPage <= 0 Then
        iPage = 1
        Else
        If iPage > Rs.PageCount Then
            iPage = Rs.PageCount
        End If
     End If
     
     If BBS_Count > 0 Then
        If BBS_Count < PageSize * iPage Then
           Size = BBS_Count - PageSize * (iPage - 1)
           Else
           Size = PageSize
        End If
        ArrayCount = Size
        ArrayItem = 11
        
        ReDim bbs_list(Size - 1, 10)
        Rs.AbsolutePage = iPage
        For i = 0 To Size - 1
            If Rs.EOF Then Exit For
            bbs_list(i, 0) = Rs("bbsid")
            bbs_list(i, 1) = Rs("deep")
            bbs_list(i, 2) = Rs("userid")
            bbs_list(i, 3) = Rs("username")
            bbs_list(i, 4) = Rs("groupid")
            bbs_list(i, 5) = Rs("title")
            bbs_list(i, 6) = Rs("time")
            bbs_list(i, 7) = Rs("see")
            bbs_list(i, 8) = Rs("best")
            bbs_list(i, 9) = Rs("faceid")
            bbs_list(i, 10) = Rs("isemail")
            Rs.MoveNext
        Next
        Set Rs = Nothing
        Else
        ArrayCount = 0
        ArrayItem = 0
     End If
     List = bbs_list
     
     'MsgBox ("Succeed")
     
     Exit Function
     
    ErrorTrap:
               ArrayCount = 0
               ArrayItem = 0
                
    End Function
      

  4.   

    和数据库连接写成DLL怎么写啊
      

  5.   

    “conn As String”<=====>“Set conn =”
    这样当然没定义好,又是一个“眼花”。
      

  6.   

    定义的是:conn As String
    赋值的是:Connstr = "....."
    晕...
      

  7.   

    set Connstr = "....."