一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務器之家 - 編程語言 - ASP教程 - javascript asp教程More About Recordsets

javascript asp教程More About Recordsets

2019-10-22 10:19asp技術網 ASP教程

javascript asp教程More About Recordsets

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 FilesCommon FilesSystemdomsado15.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">
");
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>
<TR>")
		}
	while (x <= recordCount-1)
		{
		Response.Write("<TD>" + RS.Fields(x).Value + "</TD>");
		x++;
		}
	Response.Write("</TR>
");
	RS.MoveNext();
	}
Response.Write("</TABLE>
");
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 FilesCommon FilesSystemdomsado15.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>
");
Response.Write(myArray + "<BR><BR>
")

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>
")

Response.Write("Now lets make something useful.<BR>
")
Response.Write("<TABLE BORDER=1 CELLPADDING=0 CELLSPACING=0>")
Response.Write("
<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>
<TR>")
		}
	}
Response.Write("</TR>
")
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().

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 色一情一区二区三区四区 | 厨房里摸着乳丰满在线观看 | 国产成人精品日本亚洲网址 | 70老妇牲交毛片 | 三上悠亚国产精品一区 | 久久成人伊人欧洲精品AV | 午夜神器老司机高清无码 | 女人张开腿让男人桶爽 | 欧美日韩一品道 | 幻女free性zozo交体内谢 | 国产在线观看a | 黄色cc| 色导行 | 欧美一级片免费看 | 精品国产自在在线在线观看 | 2018久久精品热在线观看 | 日本高清在线精品一区二区三区 | 国产精品合集久久久久青苹果 | 亚洲第一区欧美日韩精品 | 猛操女人 | 欧美一级专区免费大片俄罗斯 | 久久久久久久国产精品视频 | 教室里的激情电影 | 国产美女久久精品香蕉69 | 99热这里只有精品国产在热久久 | 国产精品一区二区三区免费 | 俄罗斯三级完整版在线观看 | 国内精品视频免费观看 | a∨79成人网 | 成人免费视频播放 | 思思玖玖玖在线精品视频 | 爱操综合| 18美女光胸光屁屁洗澡 | 国产在线看片护士免费视频 | 久久国产精品高清一区二区三区 | 网站国产 | 免费片在线观看 | 男人天堂影院 | 欧美xxoo做爰猛烈视频 | 999jjj在线播放 | 国产中文字幕 |