来源:www.cncfan.com | 2006-11-3 | (有2720人读过)
[二] VB源码
操作:
1、 打开VB6,修改工程名为:TestCOM,类模块名为:CDTB
2、 工程>>引用 Microsoft ActiveX Data Objects 2.7 Library (注意:版本不能太高,最好是2.8以下,否则生成DLL会出现错误)
3、 在类文件中输入如下代码
Option Explicit
Private Conn As ADODB.Connection
Public Function OpenDB(StrConn As String) As ADODB.Connection
Set Conn = New ADODB.Connection
Conn.Open StrConn
Set OpenDB = Conn
End Function
Public Sub CloseDB()
If Not (Conn Is Nothing) Then
Conn.Close
Set Conn = Nothing
End If
End Sub
Public Function Add(CD_Name As String, CD_Author As String) As Boolean
Dim Rs As New ADODB.Recordset
On Error GoTo er1
Rs.Open "Temp_CD", Conn, 1, 3
Rs.AddNew
Rs.Fields("CD_Name") = CD_Name
Rs.Fields("CD_Author") = CD_Author
Rs.Update
Add = True
Exit Function
er1:
Add = False
End Function
Public Function Delete(CD_ID As String) As Boolean
On Error GoTo er1
Conn.Execute "Delete From Temp_CD Where CD_ID = '" & CD_ID & "'"
Delete = True
Exit Function
er1:
Delete = False
End Function
Public Function Search(CD_ID As String) As ADODB.Recordset
Set Search = Conn.Execute("Select * From Temp_CD Where CD_ID = '" & CD_ID & "'")
End Function
Public Function Update(CD_ID As String, CD_Name As String, CD_Author) As Boolean
On Error GoTo er1
Conn.Execute "Update Temp_CD Set CD_Name = '" & CD_Name & "',CD_Author = '" & CD_Author & "' Where CD_ID = '" & CD_ID & "' "
Update = True
Exit Function
er1:
Update = False
End Function
4、文件>>生成TestCOM.dll
5、调试:(修改VB源码后重新生成DLL)
把如下代码保存为*.bat格式
regsvr32 -u E:\Program\VB\Test_CD\TestCOM.dll net stop "world wide web publishing service" net Start "world wide web publishing service"
|