Name

Connection.openrs — execute an SQL select statement and return the recordset

Synopsis

Recordset Connection.openrs ( sql);  
string   sql;

Description

Use this method to execute an SQL select statement and have the results returned in a Recordset object. If the SQL query is an update instead of a select then the result is undefined. If the query is invalid then null is returned and you can use the error() function to get the error message.

The SQL query should be on a single line without comments or leading or trailing whitespace.

Example 63. Connection.openrs Example

Recordset rs = conn.openrs("SELECT * FROM mytable");
if(rs == null)
{
    %><p>Error: <%=htmlencode(error())%></p><%
}
else
{
    // Do something with the results
    
    rs.close();
}

See Also

Data sources and database access in RSP is explained in the section called “Accessing Databases”