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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access