VBS的数据库操作类
类别: ASP教程
<%
class classado
Private conn_c
Private rs_c
Public strconn
Private Sub Class_Initialize\'定义类的初始化事件
End Sub
Private Sub Class_Terminate \' 设置 Terminate 事件。 \'定义类的清空事件
rs_c.close
set rs_c=nothing
conn_c.close
set conn_c=nothing
End Sub
Public Function opendb() \'打开数据库
if isempty(strconn) then
response.Write("没有设置数据库连接字符串")
response.end
end if
if isempty(conn_c) then
Set conn_c=Server.CreateObject("ADODB.Connection")
conn_c.open strconn
else
response.Write("数据库已经打开了")
response.end
end if
End Function
Public Function getrs(ByVal strsql) \'获取记录集
if isempty(conn_c) then
opendb()
end if
Set rs_c=Server.CreateObject("ADODB.RecordSet")
rs_c.Open strsql,conn_c,1,1
Set getrs=rs_c
End Function
Public Function exesql(ByVal strsql) \'执行一条sql语句,用来插入,更新,删除记录
if isempty(conn_c) then
opendb()
end if
conn_c.execute(strsql)
End Function
end class
%>
<%
\'on error resume next \'调试程序的时候请把此句去掉
strconn="Driver={sql server};server=192.168.0.110;database=northwind;uid=sa;pwd=sa;"
set c=new classado
c.strconn=strconn
c.opendb()
strsql="SELECT EmployeeID,TitleOfCourtesy + \'\' + LastName + \'\' + FirstName AS fullname FROM Employees"
arr_wawa=c.getrs(strsql).getrows()
set rs=c.getrs(strsql)
%>
<table width="100%" border="0" cellspacing="1">
<%
If not rs.eof Then
for i=0 to rs.fields.count-1
response.write rs.fields(i).name&" "
next
response.write "<br>"
do while not rs.eof
for i=0 to rs.fields.count-1
response.write rs.fields(i).value&" "
next
response.write "<br>"
rs.movenext
loop
end if
%>
<hr>
<table width="100%" border="0" cellspacing="1">
<% If not isempty(arr_wawa) Then %>
<% for i=0 to ubound(arr_wawa,2) %>
<tr>
<% for j=0 to ubound(arr_wawa,1) %>
<td><%= arr_wawa(j,i) %></td>
<% next %>
</tr>
<% next %>
<% Else %>
<tr>
<td>没有记录</td>
</tr>
<% End If %>
</table>
class classado
Private conn_c
Private rs_c
Public strconn
Private Sub Class_Initialize\'定义类的初始化事件
End Sub
Private Sub Class_Terminate \' 设置 Terminate 事件。 \'定义类的清空事件
rs_c.close
set rs_c=nothing
conn_c.close
set conn_c=nothing
End Sub
Public Function opendb() \'打开数据库
if isempty(strconn) then
response.Write("没有设置数据库连接字符串")
response.end
end if
if isempty(conn_c) then
Set conn_c=Server.CreateObject("ADODB.Connection")
conn_c.open strconn
else
response.Write("数据库已经打开了")
response.end
end if
End Function
Public Function getrs(ByVal strsql) \'获取记录集
if isempty(conn_c) then
opendb()
end if
Set rs_c=Server.CreateObject("ADODB.RecordSet")
rs_c.Open strsql,conn_c,1,1
Set getrs=rs_c
End Function
Public Function exesql(ByVal strsql) \'执行一条sql语句,用来插入,更新,删除记录
if isempty(conn_c) then
opendb()
end if
conn_c.execute(strsql)
End Function
end class
%>
<%
\'on error resume next \'调试程序的时候请把此句去掉
strconn="Driver={sql server};server=192.168.0.110;database=northwind;uid=sa;pwd=sa;"
set c=new classado
c.strconn=strconn
c.opendb()
strsql="SELECT EmployeeID,TitleOfCourtesy + \'\' + LastName + \'\' + FirstName AS fullname FROM Employees"
arr_wawa=c.getrs(strsql).getrows()
set rs=c.getrs(strsql)
%>
<table width="100%" border="0" cellspacing="1">
<%
If not rs.eof Then
for i=0 to rs.fields.count-1
response.write rs.fields(i).name&" "
next
response.write "<br>"
do while not rs.eof
for i=0 to rs.fields.count-1
response.write rs.fields(i).value&" "
next
response.write "<br>"
rs.movenext
loop
end if
%>
<hr>
<table width="100%" border="0" cellspacing="1">
<% If not isempty(arr_wawa) Then %>
<% for i=0 to ubound(arr_wawa,2) %>
<tr>
<% for j=0 to ubound(arr_wawa,1) %>
<td><%= arr_wawa(j,i) %></td>
<% next %>
</tr>
<% next %>
<% Else %>
<tr>
<td>没有记录</td>
</tr>
<% End If %>
</table>
- 上一篇: 防范SQL指令植入式攻击
- 下一篇: 破解微软脚本加密算法
-= 资 源 教 程 =-
文 章 搜 索