Option Explicit
'VB ActiveX DLL 类模块代码
'
'-----引用ASP中的一些设置------
Private ScriptingContext As ASPTypeLibrary.ScriptingContext
Private Server As ASPTypeLibrary.Server
'以下两个子程序是必须的
Public Sub OnStartPage(PassedScriptingcontext As ScriptingContext)
Set ScriptingContext = PassedScriptingcontext
Set Server = ScriptingContext.Server
End Sub
Public Sub OnEndPage()
'取消所有的引用
Set ScriptingContext = Nothing
Set Server = Nothing
End Sub
'如使用SQL的数据库,上面这些可以不要,否则要引用asp.dll Microsoft Active Server Pages Object Library
'要引用 Microsoft ActiveX Data Objects 2.8 Library
Public Function ConnS() As ADODB.Connection
Dim Con As ADODB.Connection
Set Con = New ADODB.Connection
'ACCESS
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("#webdb.mdb")
'SQL
'Con.Open "Provider = SQLoledb; User ID = sa; Password = 123456; Initial Catalog = bbs; Data Source = 192.168.0.100;"
Set ConnS = Con
Set Con = Nothing
End Function
'ASP的CONN.ASP中的写方法
Dim Conn, Con
Set Conn = Server.CreateObject("ADODB.Connection")
Set Con = Server.CreateObject("工程名称.类模块名称")
Set Conn = Con.ConnS
'ASP中就可以使用如rs.open "Select * FROM [Table]",conn,1,1、Conn.Excute("Select * FROM [Table]") 这些一样操作了
如果要求可修改的
VB中的代码如下
Public Function ConnS(ByVal DbFile As String) As ADODB.Connection
Dim Con As ADODB.Connection
Set Con = New ADODB.Connection
'ACCESS
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DbFile
Set ConnS = Con
Set Con = Nothing
End Function
'ASP的CONN.ASP中的写方法
Dim Conn, Con
Set Conn = Server.CreateObject("ADODB.Connection")
Set Con = Server.CreateObject("工程名称.类模块名称")
Set Conn = Con.ConnS(server.mappath("dbname.mdb"))