javascript asp教程はデータベース接続を作成します。


While this section is devoted to ASP database utilization、it very importent to remember that is web site is not inted to be a through ASP resource.Remember、the focus of this site is stritly stritlimited to Horipture
You'll see how to construct contruct connection streings in JavaScript、use JavaScript loops to maipulate recordsets、convert the JavaScript Date Object into a formast can accept、and to some teteextetement hone's。
You can find a lot of good resource on database utilization.Those resource,coupled with the next four lessons,will be everthing you need to write ASP JavaScript database apple.
The Connection Object:
The connection oject is the link between the database and your ASP script.Remember,it's a created or instanciated oject,so we can have twor more instancs of Connection on page.Conecte.Connection haeininininininininininincte page.Conecte page.Conecte.Conecte.Conecte hanecte hanecte.Conecte hanecte hanecte haite haite haite haite.Conecte hanecte haite haite haite haite.Conecte haethree of the methods,one of the properties、and then we will forego the rest.
The re are four common connections.1)MDL 2)DSN 3)ODBC 4)OLED E-DB.MDL stands for Microsoft Data Link.Don't use it.Also,please don't use a DSN;it's slow and outdated and nobody recompments.ODBC is better,but it's not the best.The recommand connection type is E-OLED.That's the type of connection you'll semonted below.
Get Startd:
Below is the script for Lesson 16.Don't try to understand it yet.We will slowly pick this thing appt down below.
<%@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>
Click Here to run the script in a new window.
Connection String:
This is byのmeans the most sophisticated database appication ever built、but it will demonstrate everrything we need to do.Let's start by looking at the connection string strinted 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 VB Script connection string.As mater 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 myConnect as an argment in the Open()method.
Managing the Connection:
I want you to pay atention to the next four lineas of code that I reprinted below.First we instanciate a Connect.
var ConnectObj = Server.CreateObject("ADODB.Connection");
The n we open the Connection.
ConnectObj.Open (myConnect);
The n the Connection Object becompes the second argment 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();
Next Up:
The re is a lot of code left unexplined in this example.We'll repeat the same script in lesson 17 and go over most of what we left the first time through.