<%@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 ID, colorName, hexValue FROM colorChart;";
ConnectObj.Open (myConnect);
RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);
Response.Write("<TABLE BORDER=\"1\" CELLSPACING=\"0\">\r");
Response.Write("<TR><TH>ID</TH><TH>colorName</TH>");
Response.Write("<TH>hexValue</TH></TR>\r");
while (!RS.EOF)
{
Response.Write("<TR><TD>" +RS("ID")+ "</TD><TD BGCOLOR=\"#");
Response.Write( RS("hexValue")+ "\">" + RS("colorName") );
Response.Write("</TD><TD>" +RS("hexValue")+ "</TD></TR>\r");
RS.MoveNext();
}
Response.Write("</TABLE>\r");
RS.Close();
ConnectObj.Close();
RS = null;
ConnectObj = null;
%>
</BODY>
</HTML>
[url=javascript:lesson(]Click Here[/url] to run the script in a new window.
[b]Connection String:[/b]
This is by no means the most sophisticated database application ever built, but it will demonstrate everything we need to do. Let's start by looking at the connection string reprinted below.
var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
myConnect += Server.MapPath("\\ASP")
myConnect += "\\GlobalScripts\\htmlColor.mdb;";
That does look different than a VBScript connection string. As a matter of fact, let's compare.
Dim myVBconnect;
myVBconnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=";
myVBconnect += Server.MapPath("\ASP")
myVBconnect += "\GlobalScripts\htmlColor.mdb;";
We already talked about escape characters in lesson 02. We won't revisit them here. Down below you'll see that we use [i]myConnect[/i] as an argument in the Open() method.
[b]Managing the Connection:[/b]
I want you to pay attention to the next four lines of code that I reprinted below. First we instanciate a Connection Object.
var ConnectObj = Server.CreateObject("ADODB.Connection");
Then we open the Connection.
ConnectObj.Open (myConnect);Then the Connection Object becomes the second argument in the Recordset Open() method.
RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);And lastly, when we are finished with the Connection, we close it.
ConnectObj.Close();[b]Next Up:[/b] There is a lot of code left unexplained in this example. We'll repeat the same script in lesson 17 and go over most of what we left out the first time through.
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有