用vb6编写一个最简单的dll组件
一个非常简单的vb6编写COM组件例子,将数据库链接的语句写成COM组件 打开VB,新建ActiveX Dll,将工程改名为COMConnection,类模块改名为class,在class的代码里写 :
Option Explicit
Public Function GetConn(m_objConn As Connection) As String
On Error GoTo here
Dim m_szConnstr As String
m_szConnstr = "Provider=SQLOLEDB.1;Data Source=192.168.0.101;User ID=sa;Password=;Initial Catalog=aaa"
m_objConn.Open m_szConnstr
GetConn = "OK"
Exit Function
here:
GetConn = "open database is error.error id is " & err.Description
End Function
然后编译 Asp里这样用
<%
dim obj,conn,msg
set obj=server.create("COMConnection.class")
set conn=server.create("adodb.connection")
msg=obj.GetConn(conn)
if msg="OK" then
//这里写代码,conn已经打开数据库了
else
resposne.write msg //出错了,显示出错信息
end if
%>