最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
在指定的数据库上运行SQL语句的类
时间:2022-06-30 10:21:25 编辑:袖梨 来源:一聚教程网
<%
'在指定的数据库上运行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语句
'在指定的数据库上运行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语句
相关文章
- jm漫画-在线观看最新入口 02-28
- Deepseek网页版免费入口-deepseek在线极速体验 02-28
- 哔咔-picacg核心区别 02-28
- 歪歪漫画-免费看歪歪漫画 02-28
- z-libirary软件-强大功能与独特特点 02-28
- 漫蛙manwa2最新版本下载官方正版入口-下载安装教程及常见问题解答 02-28