Below we will attempt to access data from a database without knowing the column names. Clearly the best way to utilize data in your database is to keep track of your schema. Schema is the layout of data in your database. The concept is well beyond the scope of this web site, but it is worth mentioning. Most good resources on SQL will also be good resources on database management. Better database schema leads to better ASP code.
Get Started:
Below is the script for Lesson 18.
<%@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 * FROM colorChart;"; ConnectObj.Open (myConnect); RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText); var recordCount = RS.Fields.Count; var x = 0; var getFieldNames = false; Response.Write("<TABLE BORDER=\"1\" CELLSPACING=\"0\">\r"); while (!RS.EOF) { if (x >= recordCount) { x = 0 } Response.Write("<TR>"); if (!getFieldNames) { while (x <= recordCount-1) { Response.Write("<TH>" + RS.Fields(x).Name + "</TH>"); x++; } getFieldNames = true; x = 0; Response.Write("</TR>\r<TR>") } while (x <= recordCount-1) { Response.Write("<TD>" + RS.Fields(x).Value + "</TD>"); x++; } Response.Write("</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.
I don't think this needs much explaining. The
Another Way:
A potentially more elegant way to accomplish this same goal is to use the ADO Method GetRows. It returns a multi-dimensional array containing the Recordset data. WAIT! Aren't JavaScript Arrays lexical (and flat)? Yes. We can emulate multi-dimensional arrays, but in reality they are flat. So it's a no-go on the GetRows... unless we do something really creative.
<%@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 * FROM colorChart;"; ConnectObj.Open (myConnect); RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText); var myArray = RS.GetRows().toArray(); Response.Write("Let's see the results of myArray as JavaScript"); Response.Write(" sees them (which is flat).<BR>\r"); Response.Write(myArray + "<BR><BR>\r") RS.MoveFirst(); var myVBArray = new VBArray(RS.GetRows()) Response.Write("We can use the <I>new VBArray</I> constructor and the ") Response.Write("<I>getItem( )</I> method. For example: myVBArray.getItem(1,1) ") Response.Write("returns " + myVBArray.getItem(1,1) + "<BR><BR>\r") Response.Write("Now lets make something useful.<BR>\r") Response.Write("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>") Response.Write("\r<TR>") for (var x=0; x<=myArray.length-1; x++) { Response.Write("<TD>" + myArray[x] + "</TD>") if ((x+1)%RS.Fields.Count==0) { Response.Write("</TR>\r<TR>") } } Response.Write("</TR>\r") Response.Write("</TABLE>") RS.Close(); RS = null; ConnectObj.Close(); ConnectObj = null; %> </BODY> </HTML>
Click Here to run the script in a new window.
Notice when we use getRows( ) we don't get the column names (but that would be really easy to fix). The problem with myArray is that it's not very useful in its raw state. So we use a modulo operator and thanks to a little thing called RS.Fields.Count we can tell how many times we write data to the table before staring a new table row.
If you like the new VBArray constructor you should know that you have the following methods: dimensions() getItem() lbound() toArray() and ubound().
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 群星1998《宝丽金最精彩98》香港首版[WAV+CUE][1G]
- 汪峰《也许我可以无视死亡》星文[WAV+CUE][1G]
- 李嘉-1991《国语转调2》[天王唱片][WAV整轨]
- 蔡琴2008《金声回忆录101》6CD[环星唱片][WAV整轨]
- 群星《2024好听新歌36》AI调整音效【WAV分轨】
- 梁朝伟.1986-朦胧夜雨裡(华星40经典)【华星】【WAV+CUE】
- 方芳.1996-得意洋洋【中唱】【WAV+CUE】
- 辛欣.2001-放120个心【上海音像】【WAV+CUE】
- 柏菲·万山红《花开原野1》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 柏菲·万山红《花开原野2》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 潘安邦《思念精选集全纪录》5CD[WAV+CUE]
- 杨千嬅《千嬅新唱金牌金曲》金牌娱乐 [WAV+CUE][985M]
- 杨钰莹《依然情深》首版[WAV+CUE][1G]
- 第五街的士高《印度激情版》3CD [WAV+CUE][2.4G]
- 三国志8重制版哪个武将智力高 三国志8重制版智力武将排行一览