INSERT

This statement enables you to add rows of data to the database and provides the same functionality as the ADO AddNew method.

Syntax

INSERT INTO tablename [(columnname, …)] VALUES (constant, …)

Parameters

tablename
Specifies the name of the table in which to insert data.
columnname
Specifies the name of the field in which to store data. Additional columns can be specified, separated by commas.
constant
Specifies the data to store in the field from columnname. Additional constants can be specified, but there must be the same number of constants and columns.

Remarks

The INSERT INTO statement inserts a single row into the specified table. If the list of column names is not provided, then the column order is assumed to be the order used when the table was created. However, if a table contains a varbinary field, then you must provide a list of column names.

Columns of varbinary type cannot have data inserted into them.

Values for unspecified columns are set to NULL.

Example

Dim rs, i
Set rs = CreateObject("adoce.recordset")
rs.open "create table insertme (a int, b int, c int)"
rs.open "insertme", "", 1, 3
For i = 1 To 15
rs.Addnew "a", i
Next
MsgBox rs.recordcount
rs.Close
rs.open "insert into insertme (a, b, c) values (101, 102, 103)"
rs.open "insert into insertme (a) values (100)"
MsgBox "records added"
rs.open "insertme"
MsgBox rs.recordcount
rs.Close
rs.open "drop table insertme"
Set rs = Nothing