ADO "Add Record"
We can use the SQL INSERT INTO command to add records to tables in the database.
Adding Records to Tables in the Database
We want to add a new record to the Customers table in the Northwind database. First, we need to create a form that includes the input fields from which we collect data:
When the user presses the submit button, this form is sent to a file named "demo_add.asp". The file "demo_add.asp" contains code that can add a new record to the Customers table:
Important Notes
When using the INSERT command, please note the following:
If the table has a primary key, ensure that the value added to the primary key field is unique and non-empty (otherwise, the provider will not append this record, or an error may occur)
If the table has an auto-numbered field, do not include this field in the INSERT command (the value of this field is managed by the provider)
Regarding Fields with No Data
In MS Access databases, if you set the AllowZeroLength property to "Yes", you can enter zero-length strings ("") in text, hyperlink, and memo fields.
Note: Not all databases support zero-length strings, and errors may occur when adding records with blank fields. Therefore, it is important to check the data types supported by the database you are using.