⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ado_update.asp@output=print

📁 W3Schools tutorial..web designing
💻 ASP@OUTPUT=PRINT
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>ADO Update Records</title>
 
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />

<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>

</head>
<body>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

<h1>ADO Update Records</h1>
<a href="ado_add.asp"><img border="0" src="../images/btn_previous.gif" alt="prev" width="100" height="20" /></a>
<a href="ado_delete.asp"><img border="0" src="../images/btn_next.gif" alt="next" width="100" height="20" /></a>
<hr />

<p class="intro">We may use the SQL UPDATE command to update a record in a 
table in a database.&nbsp;</p>
<hr />
<h2>Update a Record in a Table</h2>
<p>We want to update a record in the Customers table in the Northwind database. 
We first create a table that lists all records in the Customers table:</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr>
    <td>
      <pre>&lt;html&gt;
&lt;body&gt;
&lt;%
set conn=Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Provider=&quot;Microsoft.Jet.OLEDB.4.0&quot;
conn.Open &quot;c:/webdata/northwind.mdb&quot;
set rs=Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.open &quot;SELECT * FROM customers&quot;,conn
%&gt;</pre>
      <pre>&lt;h2&gt;List Database&lt;/h2&gt;
&lt;table border=&quot;1&quot; width=&quot;100%&quot;&gt;
&lt;tr&gt;
&lt;%
for each x in rs.Fields
  response.write(&quot;&lt;th&gt;&quot; &amp; ucase(x.name) &amp; &quot;&lt;/th&gt;&quot;)
next
%&gt;
&lt;/tr&gt;
&lt;% do until rs.EOF %&gt;
&lt;tr&gt;
&lt;form method=&quot;post&quot; action=&quot;demo_update.asp&quot;&gt;
&lt;%
for each x in rs.Fields
  if lcase(x.name)=&quot;customerid&quot; then%&gt;
    &lt;td&gt;
    &lt;input type=&quot;submit&quot; name=&quot;customerID&quot; value=&quot;&lt;%=x.value%&gt;&quot;&gt;
    &lt;/td&gt;
  &lt;%else%&gt;
    &lt;td&gt;&lt;%Response.Write(x.value)%&gt;&lt;/td&gt;
  &lt;%end if
next
%&gt;
&lt;/form&gt;
&lt;%rs.MoveNext%&gt;
&lt;/tr&gt;
&lt;%
loop
conn.close
%&gt;
&lt;/table&gt;</pre>
      <pre>&lt;/body&gt;
&lt;/html&gt;</pre>
    </td>
  </tr>
</table>
<p>If the user clicks on the button in the &quot;customerID&quot; column he or she will be 
taken to a new file called &quot;demo_update.asp&quot;. The &quot;demo_update.asp&quot; file 
contains the source code on how to create input fields based on the fields from 
one record in the database table. It also contains a &quot;Update record&quot; button 
that will save your changes:</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr>
    <td>
    <pre>&lt;html&gt;
&lt;body&gt;</pre>
    <pre>&lt;h2&gt;Update Record&lt;/h2&gt;
&lt;%
set conn=Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Provider=&quot;Microsoft.Jet.OLEDB.4.0&quot;
conn.Open &quot;c:/webdata/northwind.mdb&quot;</pre>
    <pre>cid=Request.Form(&quot;customerID&quot;)</pre>
    <pre>if Request.form(&quot;companyname&quot;)=&quot;&quot; then
  set rs=Server.CreateObject(&quot;ADODB.Recordset&quot;)
  rs.open &quot;SELECT * FROM customers WHERE customerID='&quot; &amp; cid &amp; &quot;'&quot;,conn
  %&gt;
  &lt;form method=&quot;post&quot; action=&quot;demo_update.asp&quot;&gt;
  &lt;table&gt;
  &lt;%for each x in rs.Fields%&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;%=x.name%&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name=&quot;&lt;%=x.name%&gt;&quot; value=&quot;&lt;%=x.value%&gt;&quot;&gt;&lt;/td&gt;
  &lt;%next%&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Update record&quot;&gt;
  &lt;/form&gt;
&lt;%
else
  sql=&quot;UPDATE customers SET &quot;
  sql=sql &amp; &quot;companyname='&quot; &amp; Request.Form(&quot;companyname&quot;) &amp; &quot;',&quot;
  sql=sql &amp; &quot;contactname='&quot; &amp; Request.Form(&quot;contactname&quot;) &amp; &quot;',&quot;
  sql=sql &amp; &quot;address='&quot; &amp; Request.Form(&quot;address&quot;) &amp; &quot;',&quot;
  sql=sql &amp; &quot;city='&quot; &amp; Request.Form(&quot;city&quot;) &amp; &quot;',&quot;
  sql=sql &amp; &quot;postalcode='&quot; &amp; Request.Form(&quot;postalcode&quot;) &amp; &quot;',&quot;
  sql=sql &amp; &quot;country='&quot; &amp; Request.Form(&quot;country&quot;) &amp; &quot;'&quot;
  sql=sql &amp; &quot; WHERE customerID='&quot; &amp; cid &amp; &quot;'&quot;
  on error resume next
  conn.Execute sql
  if err&lt;&gt;0 then
    response.write(&quot;No update permissions!&quot;)
  else 
    response.write(&quot;Record &quot; &amp; cid &amp; &quot; was updated!&quot;)
  end if 
end if
conn.close
%&gt;</pre>
    <pre>&lt;/body&gt;
&lt;/html&gt;</pre>
    </td>
  </tr>
  </table>
  <br />
<hr />
<a href="ado_add.asp"><img border="0" src="../images/btn_previous.gif" alt="prev" width="100" height="20" /></a>
<a href="ado_delete.asp"><img border="0" src="../images/btn_next.gif" alt="next" width="100" height="20" /></a>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -