|
 |
By using the cmdSelect object and its associated methods you can read records from a data table. You can also read selectively from a data table by specifying filter, column and sort parameters.
Constructor
[new] cmdSelect
(tablename) |
Constructs and returns a new cmdSelect object instance. The tablename string argument designates the name of the table from which records are to be selected. The tablename argument must appear within quotes. |
|
Instance Methods
execute |
Reads from the specified data table, according to the cmdSelect object's filter, columns, and sort settings. Returns a Resultset object. |
getColumns |
Returns the cmdSelect object's columns list, as set by the setColumns() method. |
getFilter |
Returns the cmdSelect object's filter, as set by the setFilter() method. |
getSort |
Returns the cmdSelect object's sort list, as set by the setSort() method. |
getTablename |
Returns the name of the table specified by the cmdSelect constructor. |
setColumns |
Specifies the column list for the cmdSelect object. |
setFilter |
Sets the filter for the cmdSelect object. |
setSort |
Specifies the sort order for the cmdSelect object. |
|
Example
The following example reads from the AddressBook data table and returns records where the LastName field has the value "Smith". For more information about this example, see the Resultset object and the next() method
//Creates a new cmdSelect object and identifies the
//data table to be selected from.
var sel = new cmdSelect("AddressBook");
//Restricts the cmdSelect to only those records
//where the LastName field has the value "Smith".
sel.setFilter({LastName:"Smith"});
//Actually selects records from the AddressBook
//data table and assigns the returned ResultSet
//object to the variable "rs".
var rs = sel.execute();
//Prints the values for the FirstName and LastName
//fields for each record in the ResultSet "rs".
while(rs.next())
{
response.write(rs.FirstName + " " + rs.LastName + "<br>");
}
var sel = new cmdSelect("AddressBook");
sel.setFilter({LastName:"Smith"});
sel.setColumns("FirstName, LastName, Email");
var rs = sel.execute();
while(rs.next())
{
response.write(rs.LastName + "<br />");
}
|