电脑爱好者,提供IT资讯信息及各类编程知识文章介绍,欢迎大家来本站学习电脑知识。 最近更新 | 联系我们 RSS订阅本站最新文章
电脑爱好者
站内搜索: 
当前位置:首页>> Asp>>VB开发ASP组件经典事例[二]:

VB开发ASP组件经典事例[二]

来源:www.cncfan.com | 2006-11-3 | (有2728人读过)

[二] 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"







Asp热门文章排行
网站赞助商
购买此位置

 

关于我们 | 网站地图 | 文档一览 | 友情链接| 联系我们

Copyright © 2003-2024 电脑爱好者 版权所有 备案号:鲁ICP备09059398号