Show/Hide Toolbars

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

asprunnernet32x32     ASPRunner.NET 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.NET class, all fields are ASP.NET variables declared in this class.

Variables/Arrays

Variable/Array

Description

Table("TableName")

Provides access to a table.

Example:

dynamic tblCars = GlobalVars.dal.Table("Carsmake");

Value["FieldName"]

Provides access to the field values. Value["FieldName"] refers to the field to be updated or added.

Example:

dynamic tblCars = GlobalVars.dal.Table("Carsmake");
tblCars.Value["Make"] = "Volvo";

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:

dynamic tblCars2 = GlobalVars.dal.Table("Carsmake");
tblCars2.Param["Make"] = "Volvo";
tblCars2.Value["Make2"] = "v2";
tblCars2.Update();

The corresponding SQL query:

Update Carsmake set 'Make2'='v2' where 'Make'='Volvo'

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.

Examples

Before deleting a record check if related records exist

Dynamic SQL Query

Redirect to user info edit page

Show list of customer orders

Update multiple tables

See also

Using DAL functions in projects with multiple database connections