--- title: "AddNew Method Example (JScript) | Microsoft Docs" ms.prod: sql ms.prod_service: connectivity ms.technology: connectivity ms.custom: "" ms.date: "01/19/2017" ms.reviewer: "" ms.topic: conceptual dev_langs: - "JScript" helpviewer_keywords: - "AddNew method [ADO], JScript example" ms.assetid: eabdd278-6576-4be7-9315-fb79cb8ef678 author: MightyPen ms.author: genemi --- # AddNew Method Example (JScript) This example uses the [AddNew](../../../ado/reference/ado-api/addnew-method-ado.md) method to create a new record with the specified name. Cut and paste the following code to Notepad or another text editor, and save it as **AddNewJS.asp**. ``` <%@LANGUAGE="JScript" %> <%// use this meta tag instead of adojavas.inc%> Add New Method Example (JScript)

AddNew Method Example (JScript)

<% if (Request.Form("Addit") == "AddNew") { // connection and recordset variables var Cnxn = Server.CreateObject("ADODB.Connection") var strCnxn = "Provider='sqloledb';Data Source=" + Request.ServerVariables("SERVER_NAME") + ";" + "Initial Catalog='Northwind';Integrated Security='SSPI';"; var rsEmployee = Server.CreateObject("ADODB.Recordset"); //record variables var FName = String(Request.Form("FirstName")); var LName = String(Request.Form("LastName")); try { // open connection Cnxn.Open(strCnxn) // open Employee recordset using client-side cursor rsEmployee.CursorLocation = adUseClient; rsEmployee.Open("Employees", strCnxn, adOpenKeyset, adLockOptimistic, adCmdTable); rsEmployee.AddNew(); rsEmployee("FirstName") = FName; rsEmployee("LastName") = LName; rsEmployee.Update; // of course, you would normally do error handling here Response.Write("New record added.") } catch (e) { Response.Write(e.message); } finally { // clean up if (rsEmployee.State == adStateOpen) rsEmployee.Close; if (Cnxn.State == adStateOpen) Cnxn.Close; rsEmployee = null; Cnxn = null; } } %>

Please enter the record to add:

First Name:
Last Name:
``` ## See Also [AddNew Method (ADO)](../../../ado/reference/ado-api/addnew-method-ado.md) [Recordset Object (ADO)](../../../ado/reference/ado-api/recordset-object-ado.md)