javascript asp教程Recordset记录(2)

Click Here to run the script in a new window.

The DLL:

We'll dissect the Recordset statements from top to bottom. In this case that means starting with the Dynamic Link Library.

<!-- METADATA TYPE="typelib" 
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->

What in the world is a DLL? A Dynamic Link Library holds values without tying up memory. Here's how it works. If you try to use a variable that is undefined, ASP will first look it up in the DLL. You'll notice in the Recorset.Open() Method that we use variables that are not defined in the script. Thanks to the DLL, we won't get an error code.

Managing the Recordset:

First we must instanciate a Recordset, which we do in the little snippet below.

var RS = Server.CreateObject("ADODB.Recordset");

Next we create a Text Command. The text in question comes in the form of S.Q.L. (Structured Query Language). SQL is beyond the scope of this web site, but the command below means select ID, colorName and hexValue from the colorChart Table.

var sql="SELECT ID, colorName, hexValue FROM colorChart;";

Then we open the Recordset. The five arguments in order are: source, connection, cursor type, lock type, and options .

RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);

Using a loop, we tell ASP to do certain things for as long as we haven't hit EOF, which means End of File.

while (!RS.EOF)

Next, we access specific collums in the Recordset by name.

Response.Write( RS("hexValue") + "\">" + RS("colorName") );

Then we move down from one row of records to the next.

RS.MoveNext();

Finally, when we reach EOF, the loop relinquishes control and we can close the Recordset Object.

RS.Close();

The Rest of The Story:

This is by no means a complete lesson on Recordsets; it wasn't meant to be. The rest of the story on Recordsets is out there, on the internet, and in books. There is one other thing we have to talk about with Recordsets. We do that in lesson 18.

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2930.html