Wise ASP Logo Surfer's Choice Member
   

Wise ASP - The Recordset Object

Easily reading your tables with the Recordset Object

  Here is an invaluable program that you can use to view and control the presentation of records in your database. We will use the Recordset object and the MaxRecords property via ADO, to set the number of records to return to the recordset and therefore to your screen. This is like a table in memory, holding records which are subdivided into individual fields.

Creating a Form

  First, we will create a simple form where a you can enter a "table" and the number of rows to display. The benefit of using a form is that we can type in any table in the "dsn" we are using very quickly. Please note that we are using using the POST method with the following form names: "tableName" and "numRecords".
<form name=tableForm method=POST 
    action=" <% Request.ServerVariables("script_name") %>"> 
<table width=70%> 
<THEAD> 
<TR><TH COLSPAN=2>Table View</TH> 
<TBODY> 
<TR><TD>Table Name: </TD> 
<TD><INPUT type=text name=tableName size=45 maxlength=40></TD> 
<TR><TD>Rows to display: </TD> 
<TD><INPUT type=text name=numRecords value=10 size=4 maxlength=2></TD> 
</table> 
<input type=submit value=Submit name=submit> 
</form>  

Creating Recordsets Directly

  Now, we need to prepare for when the user hits submit. First, we need to get access to our data source. But, we don't need to maintain a connection for several operations, we can simply create a recordset directly. The connection is still created in the background automatically.

  To create the object, we will first create an instance of a recordset object using the Server.CreateObject. Then we will use the Open method of the recordset to use our data source.

var RS = Server.CreateObject("ADODB.Recordset"); 
var connStr="DSN=myDB;uid=userId;pwd=passWord;" 
RS.CursorLocation=3; // adUseClient; 
RS.CacheSize=10; 

Creating the SQL Statement

  After the user hits the submit button from our form, we can retrieve the form elements from the collection. We will use the table name and the number of records to set up our recordset. Below is the code to setup our query and execute it. These lines of code will be included in the head section of your html file when the "Submit" was depressed.

RS.PageSize=Request.Form("numRecords");  // number of records 
 
var sql; 
sql = "SELECT * " 
sql += "FROM " + Request.Form("tableName") 

RS.open(sql,connStr); 

if (RS.eof) { 
  write("No rows found."); 
  write("Please use your brower's "Back" button to retry."); 
  return; 
} 
    Stay Here Page 2 Page 3 Page 4
    88x31cardsvisoranm