2009年3月7日星期六

十天学会ASP之第七天

学习目的:学会数据库的基本操作3(删除记录)
开门见山,大家直接看程序。
exec="delete * from guestbook where id="&request.form("id")
上面这句话完成了删除记录的操作,不过锁定记录用了记录唯一的表示id,我们前面建立数据库的时候用的是系统给我们的主键,名字是编号,由于是中文的名字不是很方便,大家可以修改为id,不修改的话就是
exec="delete * from guestbook where 编号="&request.form("id")
下面我们看完整的代码:一个表单传给ASP文件一个ID,然后这个ASP文件就删除了这个ID。

delete:




example7.asp:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")
exec="delete * from guestbook where 编号="&request.form("id")
conn.execute exec
%>
我在示例里面加了一个example72.asp,和example4.asp差不多,就是加了一个id字段,大家可以先运行这个文件看一下所有记录的ID和想删除记录的ID,删除记录以后也可以通过这个文件复查。等到最后一天,我们会把所有的这些东西整合的。大家就不会需要这么麻烦的操作。

example72.asp:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("example3.mdb")
exec="select * from guestbook"
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,1
%>


无标题文档






<%
do while not rs.eof
%>






<%
rs.movenext
loop
%>
<%=rs("编号")%> <%=rs("name")%> <%=rs("tel")%> <%=rs("message")%> <%=rs("time")%>





没有评论:

wholesale retail company from china

achinaseller.com is a professional wholesale retail company, having our own factory with 5 years of wholesale retail experience. Achinaseller.com is also cooperating closely with many factories, so the price that we offer to the consumer is directly from the Chinese Factory. Without leaving your home, you could order your own products at achinaseller.com at the lowest price.
We service over 100,000 registered buyers, delivering to virtually every country in the world. Our warehouse and office are staffed by a young team of Chinese and Western staff.
Happy AchinaSeller buyers include frequent wholesale importers, famous ecommerce websites, eBay powersellers, retail shops and startup home import businesses. On a daily basis, we serve corporate buyers, drop-ship experts, home business Moms, and small bussiness wholesaler