CodeCharge Studio

Execute Method (ASP)

Applies to

Connection Object

Syntax

<connection>.Execute query
Set <recordset> = <connection>.Execute(query)

Return value

ADODB.Recordset

Parameters

Name Type Description Required
query string or ADODB.Command object String containing an SQL query to be executed against the database or an ADODB.Command object to execute. Yes

Description

This method executes a specified SQL query against the database connection.

The first syntax shown above is used when the query will not return a recordset (e.g. INSERT/UPDATE/DELETE queries). The second syntax is used when the query will return a recordset object (e.g. SELECT query).

Examples

The following example opens a custom recordset to build a list of groups the user belongs to (comma-separated). Recordset is iterated, string built and assigned to record's label control.
It assumes groups and group_users tables exist. Connection is called Connection1. UserProfile form and UserGroups label are assumed to exist. This code may be inserted into label's Before Show event.
Dim rsGroups
Dim strGroups
Dim SQL
strGroups = ""
SQL = "SELECT group_name FROM group_users gu LEFT JOIN groups g ON gu.group_id = g.group_id "&_
      "WHERE gu.user_id = " & DBConnection1.ToSQL(CCGetUserID(),ccsInteger)
Set rsGroups = DBConnection1.Execute(SQL)
While rsGroups.EOF
  strGroups = IIf(strGroups = "", rsGroups("group_name"), ", " & rsGroups("group_name"))
  rsGroups.MoveNext
Wend
UserProfile.UserGroups.Value = strGroups

See also

DataSource.SQL Property


On-line, printable versions and updates