其它的對(duì)數(shù)據(jù)記錄的操作我們新建一個(gè)類,使用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) %>
當(dāng)然你也這以這樣寫:
<% sql="insert into cnarticle(cn_title,cn_author,cn_content) values(' "&whattitle&" ',' "&whoauthor&" ',' "&whatcontent&" ')" opendatabase conn.execute(sql) closedatabase %>
考慮到可能刪除語句我們會(huì)這么寫: sql="delect from cnarticle where id in(1,3,5,6,7,8)"
我新建一個(gè)類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文件,請(qǐng)自己進(jìn)行增刪
<% '用于查詢數(shù)據(jù) 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 '查出記錄條數(shù) 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 查出記錄有數(shù) 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 '將查詢的數(shù)據(jù)全部生成隱藏值 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 %>
經(jīng)典論壇討論: http://bbs.blueidea.com/thread-2776671-1-1.html
本文鏈接:http://m.95time.cn/tech/program/2007/4880.asp
出處:藍(lán)色理想
責(zé)任編輯:moby
上一頁 asp快速開發(fā)方法之?dāng)?shù)據(jù)操作 [2] 下一頁
◎進(jìn)入論壇網(wǎng)絡(luò)編程版塊參加討論
|