2009年3月7日星期六

十天学会ASP之第八天

学习目的:学会数据库的基本操作4(修改记录)
先来看代码:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("test.mdb")//这不是以前的一个数据库,里面就aa,bb两个字段
exec="select * from test where id="&request.querystring("id")
set rs=server.createobject("adodb.recordset")
rs.open exec,conn
%>










aa bb

">

">

">


<%
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
大家到现在应该分析这个代码没有什么问题,这个代码的作用是接受前面一个页面的ID然后显示这条记录,文本框即是输入的地方也是显示的地方,如果需要修改的话修改以后按提交;如果不需要修改就可以直接按提交按钮。这里还有一个东西以前没有说,那就是隐藏的表单元素:hidden元素,里面的value是不用用户输入的,会随着表单一起提交,用于传递变量。下面是modifysave.asp的代码:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={microsoft access driver (*.mdb)};dbq="&server.mappath("test.mdb")
exec="select * from test where id="&request.form("id")
set rs=server.createobject("adodb.recordset")
rs.open exec,conn,1,3
rs("aa")=request.form("aa")
rs("bb")=request.form("bb")
rs.update
rs.close
set rs=nothing
conn.close
set conn=nothing
%>
在这里,rs.open exec,conn,1,3后面的参数是1,3,这我以前提过,修改记录就要用1,3。实际上修改记录很容易看懂,记录集是rs,rs("aa")就是当前记录aa字段的东西,让它等于新的数据request.form("aa")当然就修改了,不过最后别忘记保存,那就是rs.update!
说到这里,记录的搜索,读取,修改,插入都说了,通过这最基本的东西就可以作出复杂的东西了,外面的大型数据库:新闻系统,留言簿就是字段多一点罢了。今天的示例中的代码是结合以前的数据库的,大家DOWN了以后回去调试分析一下。(rar里面的那个example72.asp还是供大家查询记录ID和核对修改以后的记录用的)

-

资料引用:http://www.knowsky.com/4030.html

没有评论:

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