其它的对数据记录的操作我们新建一个类,使用UpdateTable来完成操作:
<% Class DataTable public Function UpdataSql(sql) If sql<>"" then Opendatabase conn.execute(sql) Closedatabase End If End Function End Class %>
<% sql = "delete from cnarticle" set UpdateDate=new DataTable UpdateDate.UpdataSql(sql) %>
当然你也这以这样写:
<% sql="insert into cnarticle(cn_title,cn_author,cn_content) values(' "&whattitle&" ',' "&whoauthor&" ',' "&whatcontent&" ')" opendatabase conn.execute(sql) closedatabase %>
考虑到可能删除语句我们会这么写: sql="delect from cnarticle where id in(1,3,5,6,7,8)"
我新建一个类DeldataTable,直接使用DeldataTable.DeldataSql(tableName,DelField,id)完成记录的删除操作。
<% Class DataTable dim tempvalue public Function DeldataSql(tableName,DelField,id) If tableName<>"" and id<>"" then sql="delete from "&tableName If isnumeric(id) and instr(id,",")=0 then sql = sql & " where "&DelField&" = "&id Else sql = sql & " where "&DelField&" in ("& id &")" End If Opendatabase conn.execute(sql) Closedatabase tempvalue=true Else tempvalue=false End If DeldataSql=tempvalue End Function End Class %>
以下是我的sql.asp文件,请自己进行增删
<% '用于查询数据 Class DataTable '查出记录 public Function SelectData(sql) If sql<>"" then opendatabase Rs.open sql,conn,1,1 If not Rs.eof then Thedata=Rs.GetRows(-1) Closedatabase Else Closedatabase End If End If SelectData=Thedata End Function '查出记录条数 public Function SelectDataNum(sql) If sql<>"" then Opendatabase Rs.open sql,conn,1,1 If not Rs.eof then Thedata=Rs.GetRows(-1) Closedatabase Num=ubound(Thedata,2) Else Closedatabase End If End If SelectDataNum=Num End Function '使用select count(*) from tablename 查出记录有数 public Function SelectCountNum(sql) If sql<>"" then Opendatabase Rs.open sql,conn,1,1 If not Rs.eof then Thedata=Rs.GetRows(-1) Closedatabase Num=Thedata(0,0) Else Closedatabase End If End If SelectCountNum=Num End Function '将查询的数据全部生成隐藏值 public Function GetHiddenData(sql) dim tempvalue If sql<>"" then Opendatabase Rs.open sql,conn,1,1 If not Rs.eof then Thedata=Rs.getRows(-1) TheFieldCount=rs.fields.count For i=0 to TheFieldCount-1 TheFieldList = TheFieldList & Rs.fields(i).name & "," Next Closedatabase TheField = split(TheFieldList,",") For i=0 to TheFieldCount-1 tempvalue = tempvalue & "<input type=""hidden"" id="""&TheField(i)&""" name="""&TheField(i)&""" value="""&Thedata(i,0)&""" />" Next Else Closedatabase End If End If GetHiddenData=tempvalue End Function public Function UpdataSql(sql) If sql<>"" then Opendatabase conn.execute(sql) Closedatabase End If End Function public Function DeldataSql(tableName,DelField,id) dim tempvalue If tableName<>"" and id<>"" then sql="delete from "&tableName If isnumeric(id) and instr(id,",")=0 then sql = sql & " where "&DelField&" = "&id Else sql = sql & " where "&DelField&" in ("& id &")" End If Opendatabase conn.execute(sql) Closedatabase tempvalue=true Else tempvalue=false End If DeldataSql=tempvalue End Function End Class %>
经典论坛讨论: http://bbs.blueidea.com/thread-2776671-1-1.html
本文链接:http://www.blueidea.com/tech/program/2007/4880.asp
出处:蓝色理想
责任编辑:moby
上一页 asp快速开发方法之数据操作 [2] 下一页
◎进入论坛网络编程版块参加讨论
|