国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

javascript asp教程More About Recordsets

2024-05-04 10:58:20
字體:
來源:轉載
供稿:網友

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("http://")myConnect += "http://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 RS.Fields.Count tells us how many columns wide the Recordset is. For each row, we loop through columns using either RS.Fields(x).Name for the colum name or RS.Fields(x).Value for the datum in said column.

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("http://")myConnect += "http://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>            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保定市| 三原县| 白银市| 楚雄市| 衡东县| 营口市| 山东| 西吉县| 武宣县| 徐水县| 栖霞市| 凭祥市| 翁源县| 旺苍县| 泰顺县| 永泰县| 浦江县| 鹤岗市| 共和县| 栾川县| 缙云县| 德江县| 怀化市| 太和县| 宽甸| 镇江市| 金塔县| 柳州市| 景宁| 榆中县| 新竹市| 房山区| 巴楚县| 中江县| 汉中市| 澄迈县| 松原市| 陇南市| 松江区| 芜湖县| 云浮市|