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

热门教程

在线建库

时间:2022-06-30 10:35:10 编辑:袖梨 来源:一聚教程网

<%
on error resume next
class createdb
'
'
'建立一个数据库
'用法:
'dim cdb
'set cdb=new createdb
'cdb.setdbname=数据库名
'if cdb.ifok then response.end 数据库已经存在
'cdb.run
'检查是否运行成功
'if cdb.ifok then
'response.write cdb.errs
'end if
private dbname '数据库名字
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="在线建库"
end sub
'设置数据库名
property let setdbname(byval dbn)
dbname=dbn
'检查数据库是否已经存在
ifexistdb dbn
end property
public sub run()
'
class_initialize
'检查数据库名是否为空
if isnull(dbname) or isempty(dbname) or cstr(dbname)="" then
errstr="建立数据库失败,数据库名不能为空"
ifsure=true
exit sub
end if
'这句不能放在ifexistdb里,也不能随后执行,因为找不到数据库后自动退出这个类,
'可能是太严重的错误吧,所以只能在另一个地方清理错误码了
err.clear
dim objcreate '保存ADOX.CATALOG对象
set objcreate=Server.CreateObject("adox.catalog")
if err.number<>0 then
errstr="建立adox.catalog对象失败,请检查你的用户权限。"+err.description
set objcreate=nothing
ifsure=true
exit sub
end if
'建立数据库
objcreate.create("data source="+server.mappath(dbname)+";provider=microsoft.jet.oledb.4.0")
if err.number<>0 then
errstr="建立数据库失败。
"+err.description
ifsure=true
set objcreate=nothing
exit sub
end if
'如果没有出错,设置成功标志

热门栏目