β
Home HTML JAVASCRIPT CSS VUE REACT PYTHON3 JAVA C C++ C# AI GO SQL LINUX VS CODE BOOTSTRAP GIT Local Bookmarks
ADO Tutorial
ADO Tutorial
Introduction to ADO
ADO Database Connection
ADO Recordset
ADO Display
ADO Query
ADO Sorting
ADO Adding Records
ADO Updating Records
ADO Deleting Records
ADO Script Acceleration
ADO Command Object
ADO Connection Object
ADO Error Object
ADO Field Object
ADO Parameter Object
ADO Property Object
ADO Record Object
ADO Recordset Object
ADO Stream Object
ADO Data Types
ADO Summary
ADO Examples
ADO Sorting
ADO Updating Records
In-Depth Exploration
Development Tools
Computers
Software
Web Design and Development
Computer
Web Service
Computer Science
Network Services
Computer Hardware
Programming
ADO Adding Records
We can use the SQL INSERT INTO statement to add records to a table in a database.
Adding a Record to a Table in a Database
Suppose we want to add a new record to the Customers table in the Northwind database. First, we create a form containing input fields from which we collect data:
| CustomerID: |
|
| Company Name: |
|
| Contact Name: |
|
| Address: |
|
| City: |
|
| Postal Code: |
|
| Country: |
|
When the user clicks the Submit button, the form is sent to a file named "demo_add.asp". The file "demo_add.asp" contains code that adds a new record to the Customers table:
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
sql="INSERT INTO customers (customerID,companyname,"
sql=sql & "contactname,address,city,postalcode,country)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("custid") & "',"
sql=sql & "'" & Request.Form("compname") & "',"
sql=sql & "'" & Request.Form("contname") & "',"
sql=sql & "'" & Request.Form("address") & "',"
sql=sql & "'" & Request.Form("city") & "',"
sql=sql & "'" & Request.Form("postcode") & "',"
sql=sql & "'" & Request.Form("country") & "')"
on error resume next
conn.Execute sql,recaffected
if err0 then
Β Β Response.Write("No update permissions!")
else
Β Β Response.Write("
" & recaffected & " record added
")
end if
conn.close
%>
Important Notes
When using the INSERT command, please note the following points:
If the table has a primary key, ensure that the value assigned to the primary key field is unique and non-empty (otherwise, the provider will not insert the record or an error may occur).
If the table contains an auto-incrementing field, do not include this field in the INSERT statement (its value is managed by the provider).
Handling Empty Fields
In MS Access databases, if you set the AllowZeroLength property to "Yes", you can enter zero-length strings ("") into text, hyperlink, and memo fields.
Note: Not all databases support zero-length strings, so errors may occur when adding records with empty fields. Therefore, it's important to check the data types supported by your database.
ADO Sorting
ADO Updating Records
Byte Ark Coding Plan
Supports mainstream large models such as Doubao, GLM, DeepSeek, Kimi, MiniMax, etc., directly provided by official sources for stability and reliability.
Β₯9.9
/ month
Subscribe Now
iFLYTEK Starry Sky Coding Plan
Includes free model call allowances for DeepSeek, GLM, Kimi, MiniMax, offering a one-stop experience and deployment platform.
Β₯3.9
/ month
Subscribe Now
Click to Share Notes
Category Navigation
Python / Data Science
AI / Intelligent Development
Frontend Development
Backend Development
Databases
Mobile Development
DevOps / Engineering
Programming Languages
Computer Fundamentals
XML / Web Service
.NET
Website Construction
Advertisement
ADO Tutorial
ADO Tutorial
Introduction to ADO
ADO Database Connection
ADO Recordset
ADO Display
ADO Query
ADO Sorting
ADO Adding Records
ADO Updating Records
ADO Deleting Records
ADO Script Acceleration
ADO Command Object
ADO Connection Object
ADO Error Object
ADO Field Object
ADO Parameter Object
ADO Property Object
ADO Record Object
ADO Recordset Object
ADO Stream Object
ADO Data Types
ADO Summary
ADO Examples
Online Examples
Β·HTML Examples
Β·CSS Examples
Β·JavaScript Examples
Β·Ajax Examples
Β·jQuery Examples
Β·XML Examples
Β·Java Examples
Character Sets & Tools
Β· HTML Character Set Configuration
Β· HTML ASCII Character Set
Β· JS Obfuscation/Encryption
Β· PNG/JPEG Image Compression
Β· HTML Color Picker
Β· JSON Formatter
Β· Random Number Generator
Latest Updates
Β· GraphRAG Beginner's Guide
Β· Dart Enumerations and Symbols
Β· Dart Unit Testing
Β· Dart Concurrency and Iso...
Β· Dart Streams
Β· Dart Asynchronous Programming
Β· Dart Package and Library Management
Site Information
Β· Feedback
Β· Disclaimer
Β· About Us
Β· Article Archive
Follow on WeChat
My Favorites
Bookmark Articles
Browsing History
Clear All
No records yet