More about events Home

Introduction
Welcome
System requirements
Licensing details
What is the registration
Using ASPRunner
Working with projects
Templates
What are templates
Cars
Classified ads
Events
Jobs
Knowledge base
News
Paypal
Real estate
Sporting
Vacation houses
Connecting to the database
Datasource tables
Master-details
SQL query page
About SQL query designer
Query Designer
SQL
Results
Charts
Creating chart and setting parameters
Chart appearance
Using SQL to shape chart data
Reports
Creating report and setting parameters
Report totals and layout
Choose pages
Login page
User login settings
Advanced security settings
User group permissions
Dynamic permissions
Fields order and totals
Miscellaneous settings
Choose theme
Visual Editor
About
Toolbars
Page Elements
"View as" settings
"Edit as" settings
Validation types
Lookup wizard
Events
Output directory settings
After you are done
FTP upload
FrontPage Publishing
Advanced topics
Connecting to database
Connecting to MS Access database
Connecting to MS SQL Server database
Connecting to FoxPro database
Connecting to MySQL database
Connecting to Oracle database
Connecting to MS Excel database
Connecting to CSV or Text file
Events
Data Access Layer
More about events
Global events
Table events
Page life cycle overview
Predefined actions
Send simple email
Send email with new data
Save new data in another table
Insert a record into another table
Check if specific record exists
Display a message on the Web page
Redirect to another page
Custom code
Sample code
Show list of customer orders
Check if start date is ealier than end date
Before deleting a record check if related records exist
Speed up data entry using events
Publishing ASP application to the remote Web server
Using third party FTP client to publish ASP pages to the remote Web server
Using FrontPage to publish ASP pages to the remote Web server
Demo account
What is the Demo Account?
Terms and Conditions
Enterprise Edition
Online report/chart builder
Master-details relationships
Using JOIN SQL queries
AJAX-based Functionality
ASPRunner session variables
Debugging tips
Template files processing rules (Files.txt)
Multilanguage support
Useful functions and links
ASPRunner templates
Stylesheets
Template language
Rich Text Editor plugins
How to control Inline Add/Edit functionality from script
Troubleshooting "Operation must use an updateable query" errors
ODBC
Upgrade Guide from ASPRunnerPro 4.0 and older
Frequently Asked Questions
Error: Operation must use an updateable query.
Error: Syntax error in UPDATE statement.
Error: Syntax error in INSERT INTO statement
Error: Login failed for user 'MACHINE_NAME\IUSR_MACHINE_NAME'
Error: Data type mismatch in criteria expression
Error: The Microsoft Jet database engine cannot open the file (unknown).
Error: Unable to open registry key 'Temporary (volatile) Jet DSN for process ...
Error: Data provider could not be initialized
Error: Invalid use of Null: 'Replace'
Error: Specified driver could not be loaded due to system error 5 (Oracle in OraHome92)
How can I add new ODBC Datasource
Error: Too many fields defined
Error: I enter correct login and password but receive Invalid Login error. I use SQL Server.
I cannot find ODBC Administrator applet on Windows 2000 machine
I cannot connect to my Excel (Access) database
Where can I download latest ODBC drivers
How to work with Access database stored on the remote computer?
Reserved Access, T-SQL, ODBC keywords.
Order ASPRunner online

 
 ASPRunner manual


Date Access Layer

Data Access Layer (DAL) is created to simplify and formalize work with events. This will be extremely helpful for those who don't know SQL. Also DAL allows for a merge of events from different templates (see Add template to project option) and transfer events from one project to another.

Each table is presented as ASP class, all fields are ASP variables declared in this class.

Naming convention

There are some rules how to define the field and tables names in the event code:

  • field or table name is not changed in the code if field or table name doesn't contain spaces any other other "bad" characters and do not coincide with ASP reserved words. "Good" name contains english alphabet letters, digits and underscores and starts with a letter.

  • to access table with "bad" name use Table array i.e. dal.Table("Order details")

  • to access field with "bad" name use Value array i.e. dal.Cars.Value("Year of make")

Good name examlpes

Table Cars: dal.Cars

Field YearOfMake: dal.Cars.YearOfMake

"Bad" name examples

Table "Order Details": dal.Table("Order Details")

Table Function (reserved word): dal.Table("Function")

Field Year of make: dal.Cars.Value("Year of make")

Value() and Param()

Value() and Param() arrays provide access to field values. Value("FieldName") refers to field to be updated or added, Param("FieldName") is used in the where clause of update query. This allows you to avoid the confusion when the same field appears in the field list and in WHERE clause.

Example:

dal.UsersTable.Param("FirstName")="Bob"

dal.UsersTable.Value("FirstName")="Jim"

dal.UsersTable.Update()

SQL: Update UsersTable set `FirstName`='Jim' where `FirstName`='Bob'

Data Access Layer functions:

Insert/Update/Delete functions are used to add, edit or delete record(s) in the database.

1. Add() - inserts a new record into the database

dal.EventsTable.event="First event"

dal.EventsTable.public="yes"

dal.EventsTable.Add()

Insert into EventsTable (event,public) values ('First event','yes')

2. Update() - updates one or more records in the database

dal.UsersTable.Param("ID")=32

dal.UsersTable.Value("First Name")="Jim"

dal.UsersTable.Update()

SQL: Update UsersTable set `First Name`='Jim' where ID=32

3. Delete() - deletes one or more records from the database

UsersTable.ID = 32

UsersTable.Delete()

SQL: Delete from UsersTable where ID=32

or

dal.UsersTable.FirstName="Bob"

dal.UsersTable.Email="test@test.com"

dal.UsersTable.Delete()

SQL: Delete from UsersTable where Name='Bob' and Email='test@test.com'

Query/QueryAll/FetchByID functions are used to select records from database. These functions return a resource on success, or FALSE on error. To fetch a returned row as an associative array use db_fetch_array function.

There are some rules how to define field and tables names in the event code:

  • field or table name is not changed in the code if field or table name doesn't contain spaces any other other "bad" characters and do not coincide with ASP reserved words. "Good" name contains english alphabet letters, digits and underscores and starts with a letter.

  • all spaces and "bad" characters should be replaced with undescores. to access field with "bad" name replace all "bad" characters with underscores i.e. dal.Cars.Year_of_make

  • table name should have prefix tbl if table name coincides with ASP reserved word.

 

Example:
  select and print all orders for John Sample.

Code:
  set rs = dal.OrdersTable.Query("Customer='John Sample'","OrderID DESC")
  while not rs.eof
  Response.write "Order " & rs("OrderID") & " was placed " & rs("OrderDate") & " by " & rs("Customer") & "<br>"
  rs.movenext
  wend

Output:
  Order 10456 was placed 10/10/2008 by John Sample
  Order 10512 was placed 09/09/2008 by John Sample
  Order 10689 was placed 08/08/2008 by John Sample

4. Query(where, orderby) - selects records from database sorting data by orderby field or fields and return recordsets

set rs = UsersTable.Query("Name like '%Jim%'","Email DESC")

SQL: select * from UsersTable where Name like '%Jim%' order by Email DESC

5. QueryAll() - selects all records

6. FetchByID() - selects one or more records matching the condition

UsersTable.ID=32

set rs = UsersTable.FetchByID()

SQL: select * from UsersTable where ID=32

7. TableName() - returns table name. This function is used for complex query with calculated fields or joined tables.

sql = "select sum(UnitsInStock) as total, concat(Category,' ',ProductName) as FullProductName from "

sql = sql & dal.Products.TableName() & " group by country"

 

The CHM file was converted to HTML by chm2web software.