四、Asp組件的開發與使用:
1. 組件的特點?
l 優點:
n 調用方便,節省代碼
n 安全性高
n 支援交易處理,多組件聯合
n 運行速度快
n 升級、修改組件不需修改頁面,因此擴充性好
l 缺點:
n 開發及調試困難
2. 如何使用VB開發?
⑴.開啟VB>>New Project>>ActiveX DLL
⑵.修改項目名稱為course
⑶.修改類別模組的名字為conn_db
⑷.Project>> References,引用COM+ Service Type Library和Microsoft Active Server Pages Object Library。
⑸.修改類代碼如下:
'建立資料庫連接並輸出資料庫欄位
Dim Response As Response
Dim Request As Request
Dim Server As Server
Dim Application As Application
Dim Session As Session
Private Sub Class_Initialize()
Dim objContext As ObjectContext
Set objContext = GetObjectContext()
Set Response = objContext("Response")
Set Request = objContext("Request")
Set Server = objContext("Server")
Set Application = objContext("Application")
Set Session = objContext("Session")
End Sub
Sub conn_db()
Set conn = CreateObject("adodb.connection")
conn.open "course_dsn", "course_user", "course_password"
Set rs = CreateObject("adodb.recordset")
rs.open "select * from user_info", conn, 1, 1
If rs.recordcount > 0 Then
For i = 1 To rs.recordcount
Response.write "<br>" & rs("user_name") & "<br>"
If rs.EOF Then Exit For
rs.movenext
Next
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub
⑹.添加一新類cutstr