本教程是一篇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)
%>