How to Use SQL- Insert Into Statement




SQL- Insert Into Statement

The SQL INSERT INTO Statement is the SQL code that used to insert a new data into table in database.

SQL INSERT INTO Syntax

INSERT INTO  table_name (fieldName1, fieldName2, fieldName3,…) VALUES(value_for_fieldName1, value_for_fieldName2, value_for_fieldName3,…);

SQL INSERT INTO Example

The Insert Into command can be put under the click button to add new records into a table. For example below, add a new customer name, Address, City, State from Unbound text boxes on blank form to the tbl_Customer table.

design form

Set four Unbound text boxes as following:

  1. txtName             for Customer Name field
  2. txtAddress       for Address field
  3. txtCity                 for City field
  4. txtState              for State field

VB Code under Save Customer button:

code for insert

If click on Save Customer button without entering any data, a message box “There is no data to save” will pop up as shown below.

no data to save

After entering the customer information and click Save Customer button, the data will be saved into table tbl_Customer  with a message of saving successfully.

save successfully

After click on the OK button on the message box, all text boxes will be set to blank and ready to add another customer.

blank form after save



Related posts