112
|
Chapter 6
Using Reports to Query and Update Data Sources
Specifying a Scripting Language
ASP scripts are written in VBScript, a lightweight Visual Basic-like scripting
language, or in JScript, the Microsoft version of JavaScript. ASP files should
begin with a line telling ASP which language you’re using (although a default
of VBScript is assumed if the line is omitted). Since we’re using VBScript, our
line will look like this:
<%@ LANGUAGE="VBSCRIPT"%>
Note the use of
<%
and
%>
, which identify the line as the server-side code that
ASP should process.
Selecting Database Records
Next, we’ll add a some code to define a selected set of database records. This
selection is known as a
recordset
. To come up with a recordset, we need to
know which database table to connect to, and which records to select from
that table. If your map links to a table called
Parcel_Data
through an OLE
DB data source called
Assessor
, the recordset code will look like this:
<%
Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.Open("Assessor")
SQLQuery = "SELECT * FROM Parcel_Data Where Year_Built = '1963'"
Set RS = dbConnection.Execute(SQLQuery)
%>
This might seem complicated compared to ColdFusion’s
<CFQUERY>
tag, but
it will look familiar to Visual Basic programmers. The end result is a Recordset
object variable,
RS
, which represents all houses in Parcel_Data that have a
Year_Built
value of 1963.
Note
Don’t be put off by this code if you are unfamiliar with Visual Basic. All of
your ASP database queries will follow this basic format, with only the DSN and
SQL statement varying.
Let’s go through the recordset script line by line. The first line of code uses
the
CreateObject
method of the
Server
object to create a new
Connection
object, which is assigned to the
dbConnection
variable.
Set dbConnection = Server.CreateObject("ADODB.Connection")
The next line opens a connection to the data source name (DSN), in this case
Assessor
, and assigns that connection to the
dbConnection
variable. Note
that
Open
is a method of the
Connection
object, in this case the
dbConnection variable
.
dbConnection.Open("Assessor")
Summary of Contents for 15606-011408-9300 - MAP R6.3 UPG
Page 1: ...15306 010000 5060 October 2001 Autodesk MapGuide Release 6 Developer s Guide ...
Page 6: ...vi ...
Page 16: ...16 ...
Page 30: ...30 ...
Page 84: ...84 ...
Page 134: ...134 ...
Page 202: ...202 ...