|
We may use the SQL INSERT INTO command to add a record to a table in a database. Add a Record to a Table in a Database
|
<html> <form method="post" action="demo_add.asp"> </body> |
When the user presses the submit button the form is sent to a file called "demo_add.asp". The "demo_add.asp" file contains the code that will add a new record to the Customers table:
将用户点击submit[提交]按钮后,这张表单将被发送到名为“demo_add.asp”的文件中。"demo_add.asp"文件包含了添加新记录到“Customers”表中的所有代码:
<html> <% sql="INSERT INTO customers (customerID,companyname," on error resume next |
Important
重点
If you use the SQL INSERT command be aware of the following:
你在使用SQL INSERT命令时,需要注意以下几点:
- 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)
如果该表单包含了一个私钥[primary key],那你必须要向这个私钥字段中添加一个独立的、非空值。否则,这条记录可能不会被添加,并且还会产生一个错误 - 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)
如果表单一个“AutoNumber”字段,那么请不要对这个字段使用INSERT命令(因为这个字段中的值会自动生成)。
What about Fields With no Data?
如果字段中不包含数据,那又会出现怎样的情况?
In a MS Access database, you can enter zero-length strings ("") in Text, Hyperlink, and Memo fields IF you set the AllowZeroLength property to Yes.
在MS[微软]的Access数据库中,如果你将AllowZeroLength属性设置为Yes,你就可以在文本、超链接和备注[Memo]字段中输入“零长度字符串("")”。
Note: 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.
注意:并不是所有的数据库都支持“零长度字符串("")”的;当添加一个空的字符时,可能会出现错误。其中要的一点就是:你必须检查数据库支持的数据类型。
