This example uses the AddNew method to create a new record with the specified name. Save the file as AddNewJS.asp.
<!-- BeginAddNewJS --> <% @LANGUAGE="JScript" %> <!-- Include file for JScript ADO Constants --> <!--#include File="adojavas.inc"--> <% var EmpID = String(Request.Form("EmpID").Value); var fName = String(Request.Form("FirstName").value); var mInit = String(Request.Form("MInit").Value); var lName = String(Request.Form("LastName").Value); %> <html> <head> <title>Add New Method Example (JScript)</title> <style> <!-- body { font-family: 'Verdana','Arial','Helvetica',sans-serif; BACKGROUND-COLOR:white; COLOR:black; } --> </style> </head> <body> <h1>AddNew Method Example (JScript)</h1> <% //if (EmpID.length > 0) if (Request.Form("Addit") == "AddNew") { var Connect = "Provider=sqloledb;Data Source=" + Request.ServerVariables("SERVER_NAME") + ";" + "Initial Catalog=Northwind;User Id=sa;Password=;" // Open a recordset on the Employee table using // a client-side cursor. var RsEmployee = Server.CreateObject("ADODB.Recordset"); RsEmployee.CursorLocation = adUseClient; RsEmployee.Open("Employees", Connect, adOpenKeyset, adLockOptimistic, adCmdTable); RsEmployee.AddNew(); RsEmployee.Fields("FirstName") = fName; RsEmployee.Fields("LastName") = lName; RsEmployee.Update; // Of course, you would normally do error // handling here!! Response.Write("New record added.") // Close table. RsEmployee.Close; } %> <form method="post" action="AddNewJS.asp" id=form1 name=form1> <table> <tr> <td colspan="2"> Get data from the user. </td> </tr> <tr> <td> First Name: </td> <td> <input name="FirstName" maxLength=20> </td> </tr> <tr> <td> Last Name: </td> <td> <input name="LastName" size="30" maxLength=30> </td> </tr> <tr> <td align="right"> <input type="submit" value="Submit" name="Submit"> </td> <TD align="left"> <INPUT type="reset" value="Reset" name="Reset"> </TD> </tr> </table> <INPUT type="hidden" value="AddNew" name="Addit"> </form> </body> </HTML> <!-- EndAddNewJS -->
AddNew Method | Recordset Object