Go to: Articles List

How to insert a new record into a database:

'Do database connection
sql = "insert into MyTable (COL1, COL2) values ('" & VAR1 & "'," &_
     " '" & VAR2 & "');"
Conn.Execute(sql)

      MyTable is the name of the table that you wish to use to insert your records into. COL1 and COL2 are the columns that you are going to use to put data into. VAR1 and VAR2 are the variables that represent the data you want to insert into the database.

      Notice the single quotes. In every database, each field has a type associated with it. If that field is any kind of number type, like integer, then you would not include the quotes around the values. Otherwise, for most other field types you need the single quotes.

      Once you have your sql statement set you can execute it. Here is what the above sql statement might look like once after the variables have all been inserted correctly. You can do this same thing in your own code by simply printing out the sql statement.

insert into MyTable (COL1, COL2) values ('George','Washington')

By: Josh Olson