RecordSet是另一个创建/安排对象。它是从数据库中获取的数据集合。 RecordSet具有26个属性,25种方法,11个事件和两个(2)个集合。绝大多数记录集都超出了该网站的范围。
快速一边:
我们用于第16课的数据库和第17课是MS Access 2000文件(不是大型站点的最佳数据库)。该文件称为htmlcolor.mdb,它具有一个称为colorchart的单个表。数据库表有三个列,它们称为ID,colorname和Hexvalue。
下图显示了我们将如何循环浏览这些记录。
|
|
|
在此示例中,我们按行循环循环。我们将使用movenext()方法从记录#1到#2等。然后,我们将使用列名访问每行的特定数据。
开始:
以下是第17课的脚本。它与第16课的脚本完全相同。不同之处在于,我们将重点关注与记录集有关的代码行。
<%@语言=“ javascript”%> <! - metadata type =“ typelib” file =“ c:/program files/common Files/common files/system/ado/msado15l” - > <html> <html> <body> <body> <%var myconnect =“ provider = microsoft.jet.jet.jet.oled.oledb.4.0; data source; data source; data source; data source; data source; data source; myConnect += server.mappath(“ //”); myConnect +=“ ///globalscripts//htmlcolor.mdb;“; var connectObj = server.creat.createobject(“ adodb.connection”) colorChart;“; connectObj.open(myConnect); rs.open(sql,connectObj,andyenforwardonly,adlockReadonly,adcmdText); wrespons.write.write(“ <table border =/” 1/“” cell -spacing =/“ 0/”>/r“); wress.write(“ <tr> </th> </th> <th> colorname </th>”); response.write(“ <th> hexvalue </th> </th> </tr>/r”); while(!rs.eof){! bgcolor =/“#”); wress.write(rs(“ hexvalue”) +“/”>“ + rs(“ colorname”)); wrespy.write(“ </td> <td> <td>” + rs(“ hexvalue”) + “ </td> </tr>/r”); rs.Movenex();} response.write(“ </table>/r”); rs.close(); connectObj.close(); rs = null; connectObj = null; connectObj = null;%> </body> </hody> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html> </html>