CodeCharge Studio

CCDLookUp Function (ASP)

Description

Looks up a value from the database by executing a database query against a connection. It queries a database table based on a specified filter and returns the value of the first retrieved field.

Syntax

CCDLookUp(ColumnName, TableName, Where, Connection)

Return value

variant

Parameters

Name Type Description Required
ColumnName string Database expression to evaluate. In most cases a field name. Yes
TableName string Name of the database table or view to query. Yes
Where string WHERE clause to filter the returned records. Yes
Connection clsDB<name> object Connection object to use for executing the query. Yes

Example 1

This code would usually be placed in the Before Show event of a Record form.

if tasks.EditMode then
  tasks.user_id_assign_by.Value = CCDLookUp("emp_name", "employees", "emp_id=" &_
    DBIntranetDB.ToSQL(tasks.user_id_assign_by.Value, ccsInteger) , DBIntranetDB)
else
  tasks.user_id_assign_by.Value = CCDLookUp("emp_name", "employees", "emp_id=" &)_
    DBIntranetDB.ToSQL(CCGetUserID(), ccsInteger), DBIntranetDB)
end if

Example 2

The following code uses the CCDLookUp function to lookup the sender's name and email address, and the receiver's email address for sending an email using the ASPEmail component. This code would usually be placed in the After Insert event of a Record form.

Dim Mailer 

  Set Mailer = Server.CreateObject("Persits.MailSender")
  Mailer.From = CCDLookUp("email", "employees", "emp_id=" &_
    DBIntranetDB.ToSQL(CCGetUserID(), ccsInteger), DBIntranetDB)
  Mailer.FromName = CCDLookUp("emp_name", "employees", "emp_id=" &_
    DBIntranetDB.ToSQL(CCGetUserID(), ccsInteger), DBIntranetDB)
  Mailer.AddAddress = CCDLookUp("email", "employees", "emp_id=" &_
    DBIntranetDB.ToSQL(tasks.user_id_assign_to.Value, ccsInteger), DBIntranetDB)
  Mailer.Host = "mysmtphost.com"
  Mailer.IsHTML = True
  Mailer.Subject = "New task for you"
  Mailer.Body = "A new task was assigned to you. "
  Mailer.Send
  set Mailer = Nothing


On-line, printable versions and updates