本教程是一篇asp入门篇的初级教程了,主要是讲asp access insert update delete 简单的使用哦,好了下面我们把它们写在一个函数里面然后再举例说明。
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)&"<br>"
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)
%>
……