Show/Hide Toolbars

Navigation: Advanced topics > Programming topics > Data Access Layer (DAL)

ASPRunnerPro32x32     ASPRunnerPro manual


About Data Access Layer

Scroll Prev Next More

 

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.

Variables/Arrays

Variable/Array

Description

Table("TableName")

Provides access to a table.

Example:

dal.Table("Cars")

Value("FieldName")

Provides access to the field values. Value("FieldName") refers to the field to be updated or added.

Example:

dal.Table("Cars").Value("Make")

If the field name contains only English alphabet letters, digits and underscores (doesn't contain spaces and special characters), starts with a letter and doesn't coincide with ASP reserved words, you can also use the following notation to access the field:

dal.Table("Cars").Make

Param("FieldName")

Provides access to the field values. 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.Table("UsersTable").Param("FirstName")="Bob"

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

dal.Table("UsersTable").Update()

The corresponding SQL query:

Update UsersTable set 'FirstName'='Jim' where 'FirstName'='Bob'

Methods

Method

Description

Add()

Inserts a new record into the database.

CustomQuery()

Runs custom SQL query.

Delete()

Deletes one or more records from the database.

DBLookup()

Executes an SQL query passed as a parameter and returns the first value of the first entry or null if nothing is found.

FetchByID()

Selects one or more records matching the condition.

Query()

Selects records from database sorting data by orderby field or fields and return recordset.

QueryAll()

Selects all records.

TableName()

Returns table name. This function is used for complex query with calculated fields or joined tables.

Update()

Updates one or more records in the database.

UsersTableName()

Returns properly formatted login table name.

whereAdd()

Adds new AND condition to the existing WHERE clause.

Remarks

You can use shortened DAL notation:

set dalCars=dal.Table("Cars")

set data=dalCars.Query(strWhereClause,"")

Response.Write data("Make")

Examples

Before deleting a record check if related records exist

Dynamic SQL Query

Redirect to user info edit page

Show data from master table on details view/edit/add page

Show list of customer orders

Update multiple tables

See also

Using DAL functions in projects with multiple database connections