婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > javascript asp教程More About Recordsets

javascript asp教程More About Recordsets

熱門標簽:常用地圖標注范圍點 為什么外呼系統需要預存話費呢 咸陽銷售外呼系統 外呼回撥系統圖片 離線電子地圖標注軟件注冊 企數外呼系統能用多久 寧夏怎么申請400電話 蘭州智能語音電銷機器人功能 辦理400電話一年多少錢

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>\rTR>")
		}
	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("\\")
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("\rTR>")
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>\rTR>")
		}
	}
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().

標簽:溫州 咸陽 鐵嶺 昆明 家電維修 麗江 泰州 昌都

巨人網絡通訊聲明:本文標題《javascript asp教程More About Recordsets》,本文關鍵詞  javascript,asp,教程,More,About,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《javascript asp教程More About Recordsets》相關的同類信息!
  • 本頁收集關于javascript asp教程More About Recordsets的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 措美县| 阜平县| 廉江市| 轮台县| 辉南县| 石城县| 全椒县| 和林格尔县| 民和| 崇文区| 包头市| 芦溪县| 井陉县| 邵武市| 广德县| 岑溪市| 林州市| 宜兰市| 边坝县| 永川市| 宁陕县| 沙河市| 西城区| 攀枝花市| 监利县| 什邡市| 合作市| 黎城县| 介休市| 肇庆市| 宜川县| 东山县| 利津县| 富裕县| 广德县| 深州市| 沙洋县| 犍为县| 鄂托克前旗| 上犹县| 清涧县|