javascript asp关于Recordset记录的介绍

来源:爱站网时间:2021-01-15编辑:网友分享
想必在asp编程中很多用户们都不知道Recordset记录有什么用,要如何使用Recordset记录,那么下面我们就一起去看看javascript asp关于Recordset记录的介绍。

想必在asp编程中很多用户们都不知道Recordset记录有什么用,要如何使用Recordset记录,那么下面我们就一起去看看javascript asp关于Recordset记录的介绍。

Recordset is another created/instanciated Object. It is a collection of data taken from a database. Recordset has 26 properties, 25 methods, 11 events, and two (2) collections. The vast majority of Recordset is beyond the scope of this web site.

Quick Aside:

The database we are using for lesson 16 and lesson 17 is an MS Access 2000 file (not the best database for large sites). The file is called htmlColor.mdb and it has a single Table called colorChart. The database Table has three columns and they are called ID, colorName, and hexValue.

The illustration below shows how we will cycle through these records.

 

ID colorName hexValue
1 Aqua 00FFFF
2 Beige F5F5DC
3 Crimson DC143C
4 Darkviolet 9400D3
5 ForestGreen 228B22
ID colorName hexValue
1 Aqua 00FFFF
2 Beige F5F5DC
3 Crimson DC143C
4 Darkviolet 9400D3
5 ForestGreen 228B22
ID colorName hexValue
1 Aqua 00FFFF
2 Beige F5F5DC
3 Crimson DC143C
4 Darkviolet 9400D3
5 ForestGreen 228B22

In this example we cycle through the records row by row. We will use the MoveNext() Method to go from record #1 to #2, etc. Then, we will access specific data in each row by using the column name.

Get Started:

Below is the script for Lesson 17. It's exactly the same as the script for lesson 16. The difference is that we will focus on those lines of code that deal with Recordsets.





\r");
Response.Write("
ID
colorName");
Response.Write("hexValue
\r");
while (!RS.EOF)
	{
	Response.Write("
" +RS("ID")+ "
" + RS("colorName") );
	Response.Write("
" +RS("hexValue")+ "
\r");
	RS.MoveNext();
	}
Response.Write("\r");

RS.Close();
ConnectObj.Close();
RS = null;
ConnectObj = null;
%>


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.


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.

上文就是小编分享javascript asp关于Recordset记录的介绍,ASP是一门学科,不可能使用一篇文章来讲解完,理论的东西网上很多,有兴趣的同学可以搜一搜,多了解了解。

上一篇:增加Referer功能--反向链接插件的教程

下一篇:javascript asp创建数据库连接的教程

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载