ASP直接讀取修改Access資料的示範執行個體

來源:互聯網
上載者:User
access|資料

  適合初學ASP的讀者的一篇不錯的執行個體文章,具體代碼如下:(把下面代碼儲存為1.asp)

<%
Response.Expires=0
Set 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 sql
dim i
dim 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目錄中)



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。