asp access insert update delete 使用

作者:袖梨 2022-07-02

Function add_del_update(tablename,str,id)
Select Case str
 Case "insert":
   sql="select * from ["&tablename&"] where id=null"
   rs.open sql,conn,1,3
   rs.addnew
   For Each key In request.Form
     ' response.write "rs("&CStr(key)&")="&request(key)&"
"
      rs(CStr(key))=request(key)
   Next
   rs.update
   rs.close
 Case "update":  
   sql="select * from ["&tablename&"] where id="&id
   rs.open sql,conn,1,3 
   For Each key In request.Form
      if key<>"id" then
        rs(CStr(key))=request(key)
      end if
   Next
   rs.update
   rs.close
 Case "delete":  
   sql="delete from ["&tablename&"] where id in("&id&")"
   rs.open sql,conn,1,3
 Case ""
 End Select
 End Function
%>

<%
' 向table1表中添加一条记录
 'call add_del_update("table1","insert","")
' 修改table1表中的id=5(id放在上一页action中,也可以是隐藏表单)的记录 
  'id=request("id")
  'call add_del_update("table1","update",id)
' 删除table1表中的一些记录,id是上一页action中,也可以是某一表单
 ' id=request("id")
 ' call add_del_update("table1","delete",id)
%>

相关文章

精彩推荐