首页 > 编程 > ASP > 正文

javascript asp教程Recordset记录

2024-05-04 11:01:55
字体:
来源:转载
供稿:网友

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.

IDcolorNamehexValue
1Aqua00FFFF
2BeigeF5F5DC
3CrimsonDC143C
4Darkviolet9400D3
5ForestGreen228B22
IDcolorNamehexValue
1Aqua00FFFF
2BeigeF5F5DC
3CrimsonDC143C
4Darkviolet9400D3
5ForestGreen228B22
IDcolorNamehexValue
1Aqua00FFFF
2BeigeF5F5DC
3CrimsonDC143C
4Darkviolet9400D3
5ForestGreen228B22

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.

<%@LANGUAGE="JavaScript"%><!-- METADATA TYPE="typelib" FILE="C:/Program Files/Common Files/System/ado/msado15.dll" --><HTML><BODY><%var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="; myConnect += Server.MapPath("//");myConnect += "//GlobalScripts//htmlColor.mdb;";var ConnectObj = Server.CreateObject("ADODB.Connection");var RS = Server.CreateObject("ADODB.Recordset");var sql="SELECT ID, colorName, hexValue FROM colorChart;";ConnectObj.Open (myConnect);RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);Response.Write("<TABLE BORDER=/"1/" CELLSPACING=/"0/">/r");Response.Write("<TR><TH>ID</TH><TH>colorName</TH>");Response.Write("<TH>hexValue</TH></TR>/r");while (!RS.EOF)	{	Response.Write("<TR><TD>" +RS("ID")+ "</TD><TD BGCOLOR=/"#");	Response.Write( RS("hexValue")+ "/">" + RS("colorName") );	Response.Write("</TD><TD>" +RS("hexValue")+ "</TD></TR>/r");	RS.MoveNext();	}Response.Write("</TABLE>/r");RS.Close();ConnectObj.Close();RS = null;ConnectObj = null;%></BODY></HTML>            
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表