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 Aess 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.
|
|
|
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 aess 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>
to run the script in a new window.
The DLL:
We'll dissect the Recordset statements from 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
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 es in the form of S.Q.L. (Structured Query Language). SQL is beyond the scope of this web site, but the mand 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 aess 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 plete lesson on Recordsets; it wasn't meant to be. The rest of the story on Recordsets is out there, on the inter, and in books. There is one other thing we have to talk about with Recordsets. We do that in lesson 18.
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程