javascript asp教程レコード
5390 ワード
Recordset is another created/instanciated Object.It is a collection of data tanten from a database.Recordset has 26 properties,25 methods,11 events,and two(2)collection.The vast majoject of Recordset best。
Quick Aide:
The database we are for lesson 16 and lesson 17 is MS Access 2000 file(not the best database for large Nates).The file is color.mdb and it has a single Table Table caled color.The bath thererese。
The illustration below shows how we will cycle through these records.
ID
colorName
hexValue
1
アクア
00 FFFF
2
Beige
F 5 F 5 DC
3
Crimson
DC 143 C
4
Darkviolet
9400 D 3
5
Forest Green
228 B 22
ID
colorName
hexValue
1
アクア
00 FFFF
2
Beige
F 5 F 5 DC
3
Crimson
DC 143 C
4
Darkviolet
9400 D 3
5
Forest Green
228 B 22
ID
colorName
hexValue
1
アクア
00 FFFF
2
Beige
F 5 F 5 DC
3
Crimson
DC 143 C
4
Darkviolet
9400 D 3
5
Forest Green
228 B 22
In this example we cycle through the records row by row.We will use the MoveNext()Method to go from recordd滯1 to to to to to to to 2,etc.The n,we will access specific data inch row bythe coname.
Get Startd:
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 on on on lines of code that deal with Recordsets.
The DLL:
We'll dissect the Recordset statement from top to bottom.In this case that means starting with the Dynamic Library.
Managing the Recordset:
First we must instanciate a Recordset,which we do in the little snippet below.
The n we open the Recordset.The five argments in order are:source,connection,cursor type,lock type,and options.
This is byのmeans a complettee lesson Recordsets;it wasn't meant to be.The rest of the story on Recordsets is out there,on the internet,and in book s.The is one other thing we have to talk aboot with Recordsets.We do that in lesson 18.
Quick Aide:
The database we are for lesson 16 and lesson 17 is MS Access 2000 file(not the best database for large Nates).The file is color.mdb and it has a single Table Table caled color.The bath thererese。
The illustration below shows how we will cycle through these records.
ID
colorName
hexValue
1
アクア
00 FFFF
2
Beige
F 5 F 5 DC
3
Crimson
DC 143 C
4
Darkviolet
9400 D 3
5
Forest Green
228 B 22
ID
colorName
hexValue
1
アクア
00 FFFF
2
Beige
F 5 F 5 DC
3
Crimson
DC 143 C
4
Darkviolet
9400 D 3
5
Forest Green
228 B 22
ID
colorName
hexValue
1
アクア
00 FFFF
2
Beige
F 5 F 5 DC
3
Crimson
DC 143 C
4
Darkviolet
9400 D 3
5
Forest Green
228 B 22
In this example we cycle through the records row by row.We will use the MoveNext()Method to go from recordd滯1 to to to to to to to 2,etc.The n,we will access specific data inch row bythe coname.
Get Startd:
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 on on on 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 statement from top to bottom.In this case that means starting with the Dynamic Library.
<!-- METADATA TYPE="typelib"
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
What in the world is a DLL?A Dynamic LiLibrararyHolds values without tying umemory.Here's how it works.If you try to use a variaablablathththisundefined、ASP will first look ituuup in the DLL.You'll notice in the Recorecoret the Recorerettttttttttweththatttttttttttttttttttttweapepepepepepeattttwithththaaattwiwiththththththat(EEEdededededededededededededededefined n'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 coes in the form of S.Q.L.(Structured Query Language).SQL is beyond the scope of is web site,but the command below means select ID,colorName and hexfromThe n we open the Recordset.The five argments in order are:source,connection,cursor type,lock type,and options.
var sql="SELECT ID, colorName, hexValue FROM colorChart;";
Using a loop,we tell ASP to do certain things for as long as we haven't hit EOF,which means End of File.RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);
Next,we access specific collums in the Recordset by name.while (!RS.EOF)
The n we move down from one row of records to the next.Response.Write( RS("hexValue") + "\">" + RS("colorName") );
Finally,when we reach EOF,the loop relinquishes control and we can close the Recordset Object.RS.MoveNext();
The Rest of The Story:This is byのmeans a complettee lesson Recordsets;it wasn't meant to be.The rest of the story on Recordsets is out there,on the internet,and in book s.The is one other thing we have to talk aboot with Recordsets.We do that in lesson 18.