最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Asp深度揭密(下)
时间:2022-07-02 23:33:24 编辑:袖梨 来源:一聚教程网
四、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
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
相关文章
- 无期迷途主线前瞻直播总结 无期迷途主线前瞻直播内容介绍 11-22
- 以下哪种非遗技艺是用针在纸上绣画 蚂蚁新村11月21日答案 11-22
- 江南百景图听风塔怎么样 11-22
- 原神恰斯卡圣遗物怎么搭配 11-22
- 2024年霸王茶姬11月22日口令是什么 2024.11.22霸王茶姬口令介绍 11-22
- 光遇11.21季节蜡烛在哪里 光遇11月21日季节蜡烛位置攻略 11-22