Accessing ADO with JScript

The JScript implementation of ActiveX Data Objects is almost identical to that of VBScript. The only difference is in the syntax. JScript server-side scripts are used within Active Server Pages and (with the help of Internet Information Server) are issued to a client web browser.

Referencing ActiveX Data Objects

Once difference between the VBScript and JScript implementations of ADO is the name of the include file for ActiveX Data Objects. In JScript, the filename is adojavas.inc. To add it to an Active Server Page, type the following line:

<!--#include file="adojavas.inc"-->

Creating ActiveX Data Objects

The first thing you need to do is create the variables that will hold your objects:

// define a variable which will be used as a reference to the
// Connection object
var con;

// define a variable which will be used as a reference to the
// Recordset object
var rec;

Once you have the variable references, you can create ActiveX Data Objects with the CreateObject function of the Server object just as in VBScript:

' create a new instance of an ADO Connection object
con = Server.CreateObject("ADODB.Connection");

' create a new instance of an ADO Recordset object
rst = Server.CreateObject("ADODB.Recordset");

Again, always remove your unused objects by setting them to null:

' remove the objects 
con = null;
rst = null;

Using ADO with JScript: An Example

The last example in this chapter is very similar to the VBScript example. The JScript program in Example 3-5 illustrates ...

Get ADO: ActiveX Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.