CodeCharge Studio All ASP PHP Perl ColdFusion Java C#.NET VB.NET

Dynamically Modify the SQL Statement

This example shows how to modify the SQL statement that is used to retrieve records for a Grid form. The example shows a Grid called Tasks that is based on the tasks database table.

ASP

  1. Add the Before Build Select event to the Grid.
  2. Within the event, add the code below:
Function Tasks_DataSource_BeforeBuildSelect(Sender) 

  Tasks.DataSource.SQL =  "SELECT * FROM Tasks"

End Function

PHP

  1. Add the Before Execute Select event to the Grid.
  2. Within the event, add the code below:
function Tasks_DataSource_BeforeExecuteSelect(& $sender) {
global $Tasks;

  $Tasks->DataSource->SQL = "SELECT * FROM Tasks";

}

Perl

  1. Add the Before Execute Select event to the Grid.
  2. Within the event, add the code below:
sub Tasks_DataSource_BeforeExecuteSelect() {

  $Tasks->{DataSource}->{SQL} = "SELECT * FROM Tasks";

}

Java

  1. Add the Before Execute Select event to the Grid.
  2. Within the event, add the code below:
//Tasks_BeforeExecuteSelect

  e.getCommand().setSql("SELECT * FROM Tasks");

VB.Net

  1. Add the Before Execute Select event to the Grid.
  2. Within the event, add the code below:
'Tasks_BeforeExecuteSelect

CType(Select_,TableCommand).SqlQuery = new StringBuilder("select top 3 * from ages")

C#

  1. Add the Before Execute Select event to the Grid.
  2. Within the event, add the code below:
//Tasks_BeforeExecuteSelect

((TableCommand)Select).SqlQuery = new StringBuilder("select top 3 * from ages");

See Also:

Before Build Select event, Before Execute Select event


On-line, printable versions and updates