ASP直接讀取修改Access數據的演示實例->>網頁教學網Webjx.Com 提供最新最...
適合初學ASP的讀者的一篇不錯的實例文章,具體代碼如下:(把下面代碼保存為1.asp)
<%Response.Expires=0Set Conn=Server.CreateObject("ADODB.Connection")Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("mdb/demo.mdb") & ";Mode=ReadWrite|Share Deny None;Persist Security Info=False"%><HTML><HEAD><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><style><!--.p1 {FONT-SIZE: 9pt}.l1 {BORDER: #000080 2px solid}--></style></HEAD><BODY><TABLE cellPadding=0 cellSpacing=10 class=l1><TR><TD><TABLE class=p1><%dim sqldim idim outstr If Request.ServerVariables("Request_Method")="GET" then sql="select * from admin" Set RS=Server.CreateObject("ADODB.RecordSet") RS.Open sql,conn,3,2 outstr="<FORM name=forma action=1.asp method=post>" outstr=outstr & "<TR><TD align=middle>帳號</TD><TD align=middle>密碼</TD></TR>" for i=1 to 3 if i<=RS.RecordCount then outstr=outstr & "<TR><TD><INPUT class=p1 name=t1" & i & " size=20 value=" & chr(34) & RS("帳號") & chr(34) & "></TD><TD><INPUT class=p1 name=t2" & i & " size=20 value=" & chr(34) & RS("密碼") & chr(34) & "></TD></TR>" RS.MoveNext else outstr=outstr & "<TR><TD><INPUT class=p1 name=t1" & i & " size=20></TD><TD><INPUT class=p1 name=t2" & i & " size=20></TD></TR>" end if next Response.Write(outstr)%><TR><TD align=middle colSpan=2><A href="javascript:document.forma.submit();">修改數據</A></TD></TR><% Conn.Close Set Conn=Nothing else Set RS=Conn.Execute("delete * from admin") for i=1 to 3 sql="insert into admin (帳號,密碼) values("" & Request.Form("t1" & i) & "","" & Request.Form("t2" & i) & "")" Set RS=Conn.Execute(sql) next%><TR><TD align=middle class=p5>修改操作成功<BR><BR><A href="1.asp">顯示數據</A></TD></TR><% Conn.Close Set Conn=Nothing end if%></TABLE></TD></TR></TABLE></BODY></HTML>
最後給大家提供一下文章中所用到的資料庫:點擊這裡下載資料庫文件(注意:把下載資料庫文件改名為demo.mdb放到mdb目錄中)
推薦閱讀:
※為什麼虛擬現實網頁可能永不會實現
※【問題解答】python解析網頁源代碼返回亂碼問題 | 在路上
※【背景圖片】【製作網頁素材篇】精美背景素材
※超實用的網頁設計構圖原則