ADO Add

ADO allows you to add new records to a database table using the Recordset.AddNew method. This makes it easy to insert data dynamically into your database.

Key Topics

Adding Records

Example

<%
    Dim conn, rs
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=MyDatabase;User ID=myUser;Password=myPassword;"

    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open "Employees", conn, 1, 3

    rs.AddNew
    rs("EmployeeName") = "Jane Doe"
    rs("Department") = "HR"
    rs.Update

    Response.Write("New record added successfully.")

    rs.Close
    conn.Close
    Set rs = Nothing
    Set conn = Nothing
%>

Explanation: This example demonstrates adding a new employee to the Employees table using the AddNew and Update methods of the Recordset.

Key Takeaways

  • Use the AddNew method to insert new records into a database table.
  • Ensure to call the Update method to save changes to the database.
  • ADO simplifies dynamic record insertion for web applications.