一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

在指定的数据库上运行SQL语句的类

时间:2008-01-19 编辑:简简单单 来源:一聚教程网

<%
'在指定的数据库上运行SQL语句的类
'使用方法:
'dim runs
'set runs=new runsql
'runs.setdbn=数据库名
'if runs.ifok then
' response.write runs.errs
' response.end
'end if
'runs.setsql=sql
'runs.run
'if runs.ifok then
' response.write runs.errs
' response.end
'else
' response.write "执行成功"
'end if
on error resume next
class runsql
private dbname '数据库名
private sql '要执行的SQL语句
private ifsure '用来保存是否成功的标志,如果成功值为false,失败为true,初值为true
private errstr '保存说明错误的文字
'获取ifsure值
property get ifok()
ifok=ifsure
end property
'获取errstr值
property get errs()
errs=errstr
end property
'
private sub class_initialize()
'设置ifsure,errstr的初值
ifsure=true
errstr="对指点数据库执行SQL语句"
end sub
'给dbname赋值
property let setdbn(dbn)
dbname=dbn
ifexistdb dbn
end property
'给SQL赋值
property let setsql(s)
sql=s
end property
'执行操作
public sub run()
'还原类状态
class_initialize
'检查参数是否已经填写完整
if isnull(dbname) or isempty(dbname) or cstr(dbname)="" then
errstr="dbname不能为空"
exit sub
end if
if isnull(sql) or isempty(sql) or cstr(sql)="" then
errstr="sql不能为空"
exit sub
end if
dim conn '连接数据库对象
set conn=Server.CreateObject("adodb.connection")
if err.number<>0 then
errstr="建立adodb.connection对像失败."
set objcreate=nothing
exit sub
end if
errstr="不能连接数据库"
'连接数据库
conn.connectionstring="provider=microsoft.jet.oledb.4.0;data source="+server.mappath(dbname)
conn.open
errstr="执行SQL语句失败"
'执行SQL语句

热门栏目