最新下载
热门教程
- 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
相关文章
- 《无限暖暖》天星之羽获得位置介绍 12-20
- 《流放之路2》重铸台解锁方法介绍 12-20
- 《无限暖暖》瞄准那个亮亮的成就怎么做 12-20
- 《无限暖暖》魔气怪终结者完成方法 12-20
- 《无限暖暖》曙光毛团获得位置介绍 12-20
- 《无限暖暖》日光果获得位置介绍 12-20