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

📄 ado_add.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 Add 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 Add Records</h1>
<a href="ado_sort.asp"><img border="0" src="../images/btn_previous.gif" alt="prev" width="100" height="20" /></a>
<a href="ado_update.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 INSERT INTO command to add a record to a 
table in a database.&nbsp;</p>
<hr />
<h2>Add a Record to a Table in a Database</h2>
<p>We want to add a new record to the Customers table in the Northwind database. 
We first create a form that contains the fields we want to collect data from:</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr>
    <td>
      <pre>&lt;html&gt;
&lt;body&gt;</pre>
      <pre>&lt;form method=&quot;post&quot; action=&quot;demo_add.asp&quot;&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;CustomerID:&lt;/td&gt;
&lt;td&gt;&lt;input name=&quot;custid&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;Company Name:&lt;/td&gt;
&lt;td&gt;&lt;input name=&quot;compname&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;Contact Name:&lt;/td&gt;
&lt;td&gt;&lt;input name=&quot;contname&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;Address:&lt;/td&gt;
&lt;td&gt;&lt;input name=&quot;address&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;City:&lt;/td&gt;
&lt;td&gt;&lt;input name=&quot;city&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;Postal Code:&lt;/td&gt;
&lt;td&gt;&lt;input name=&quot;postcode&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;&lt;tr&gt;
&lt;td&gt;Country:&lt;/td&gt;
&lt;td&gt;&lt;input name=&quot;country&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; value=&quot;Add New&quot;&gt; 
&lt;input type=&quot;reset&quot; value=&quot;Cancel&quot;&gt;
&lt;/form&gt;</pre>
      <pre>&lt;/body&gt;
&lt;/html&gt;</pre>
    </td>
  </tr>
</table>
<p>When the user presses the submit button the form is sent to a file called &quot;demo_add.asp&quot;. 
The &quot;demo_add.asp&quot; file contains the code that will add a new record to the 
Customers table:</p>
<table class="ex" cellspacing="0" border="1" width="100%" cellpadding="3">
  <tr>
    <td>
    <pre>&lt;html&gt;
&lt;body&gt;</pre>
    <pre>&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>sql=&quot;INSERT INTO customers (customerID,companyname,&quot;
sql=sql &amp; &quot;contactname,address,city,postalcode,country)&quot;
sql=sql &amp; &quot; VALUES &quot;
sql=sql &amp; &quot;('&quot; &amp; Request.Form(&quot;custid&quot;) &amp; &quot;',&quot;
sql=sql &amp; &quot;'&quot; &amp; Request.Form(&quot;compname&quot;) &amp; &quot;',&quot;
sql=sql &amp; &quot;'&quot; &amp; Request.Form(&quot;contname&quot;) &amp; &quot;',&quot;
sql=sql &amp; &quot;'&quot; &amp; Request.Form(&quot;address&quot;) &amp; &quot;',&quot;
sql=sql &amp; &quot;'&quot; &amp; Request.Form(&quot;city&quot;) &amp; &quot;',&quot;
sql=sql &amp; &quot;'&quot; &amp; Request.Form(&quot;postcode&quot;) &amp; &quot;',&quot;
sql=sql &amp; &quot;'&quot; &amp; Request.Form(&quot;country&quot;) &amp; &quot;')&quot;</pre>
    <pre>on error resume next
conn.Execute sql,recaffected
if err&lt;&gt;0 then
  Response.Write(&quot;No update permissions!&quot;)
else 
  Response.Write(&quot;&lt;h3&gt;&quot; &amp; recaffected &amp; &quot; record added&lt;/h3&gt;&quot;)
end if
conn.close
%&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
    </td>
  </tr>
  </table>
  <br />
<hr />
<h2>Important</h2>
<p>If you use the SQL INSERT command be aware of the following:</p>
<ul>
  <li>If the table contains a primary key, make sure to append a unique, 
non-Null value to the primary key field (if not, the provider may not append the 
  record, or an error occurs)</li>
  <li>If the table contains an AutoNumber field, do not include this field in 
  the SQL INSERT command (the value of this field will be taken care of 
  automatically by the provider)</li>
</ul>
<hr />
<h2>What about Fields With no Data?</h2>
<p>In a MS Access database, you can enter zero-length strings (&quot;&quot;) in Text, 
Hyperlink, and Memo fields IF you set the AllowZeroLength property to 
Yes.</p>
<p><b>Note: </b>Not all databases support zero-length strings and may cause an 
error when a record with blank fields is added. It is important to check what 
data types your database supports.<br />
</p>
<hr />
<a href="ado_sort.asp"><img border="0" src="../images/btn_previous.gif" alt="prev" width="100" height="20" /></a>
<a href="ado_update.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 + -