一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - ASP教程 - javascript asp教程Recordset記錄

javascript asp教程Recordset記錄

2019-10-22 10:19asp技術網 ASP教程

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.

<%@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>

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.

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩人成免费网站大片 | 日本一卡二卡3卡四卡无卡网址 | 激情婷婷成人亚洲综合 | 日本精品一卡二卡≡卡四卡 | yellow视频免费观看播放 | 国产私拍精品88福利视频 | 日韩精品一区二三区中文 | 国产馆精品推荐在线观看 | 99视频精品全部免费观看 | 精品免费视在线观看 | 3d动漫h在线观看网站蜜芽 | 日本tube24xxxxx | 国产二区视频 | 国产成人久久久精品一区二区三区 | 末代皇帝无删减版在线观看 | 日本人作爰啪啪全过程 | 热久久亚洲 | 99在线精品日韩一区免费国产 | 色妞视频一级毛片 | 日本视频一区在线观看免费 | 4438成人网| 国内体内she精视频免费 | 亚洲网站在线观看 | 亚洲国产精品久久网午夜小说 | 美女被躁了在线观看视频 | 日本成人免费在线视频 | 希望影院高清免费观看视频 | 欧美香蕉人人人人人人爱 | 男人的天堂视频 | 处女呦呦| 日本高清有码视频 | 成人先锋 | 91最新国产 | 视频一区国产精戏刘婷30 | 欧美腐剧mm在线观看 | 四虎新网站 | 亚洲视频免费 | 微福利92合集 | 狠狠综合久久综合网站 | 美女和男人一起差差 | 毛片视频网站在线观看 |