|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
<% \\\'在指定的数据库上运行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语句 conn.execute(sql) \\\'假如没出错 设置成功标志 if err.number=0 then ifsure=false end if end sub private sub ifexistdb(byval dbn) \\\'还原类状态 class_initialize \\\'假如数据库存在,就设为true,因为假如不存在的话就不能继承执行这个类 \\\'检查数据库是否已经存在 errstr="数据库不存在" dim conn set conn=server.createobject("adodb.connection") conn.connectionstring="provider=microsoft.jet.oledb.4.0;data source="+server.mappath(dbn) conn.open if err.number=0 then ifsure=false end if end sub end class %> 返回类别: 教程 上一教程: ASP OBJECT之:EXPIRESABSOLUTE 下一教程: ASP讲座之五:ASP组件 您可以阅读与"在指定的数据库上运行SQL语句的类"相关的教程: · 一条SQL语句搞定数据库分页 · 多图片上传到指定的目录并存到数据库 · ASP中使用SQL语句操作数据库 · 一条SQL 语句搞定数据库分页 · 用ASP实现多图片上传到指定的目录并存到数据库 |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |