Asp深度揭密(下)

作者:袖梨 2022-07-02
四、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 "
" & rs("user_name") & "
"
If rs.EOF Then Exit For
rs.movenext
Next
End If
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
End Sub
⑹.添加一新类cutstr

相关文章

精彩推荐