Add records

Records can be added into the table in two ways:-

 

Method 1

AddNew method of the Recordset object adds a blank record to the table. Update method of the recordset saves the record added to the table.

 Syntax:-

Rsobject1.AddNew            where Rsobject1 is the name of the recordset.

Example:-

<%

rsstudent.AddNew
rsstudent.Fields("FirstName") = “Sandra”
rsstudent.Fields("Age") = 25
rsstudent.Update

%>

where rsstudent is a  variable of recordset object, Firstname and Age are  the names of fields in a table.

 NOTE:- Connect to the database and open the recordset before using the above code 

Method 2

Execute method of the Connection object executes an SQL statement such as insert, update and delete.

 Syntax:-

Connobject1.Execute (sql) where sql statement is a valid INSERT statement and Connobject1 is the name of a connection object.

 Example:-

Strinsert =”Insert into student (name, age) values (‘sandra’, 20)”           

Connect1.execute (strinsert)

where Connect1 is a variable of connection object and strinsert is a variable name.

NOTE:- Connect to the database before using the above code (method 2)