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

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

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

服務(wù)器之家 - 編程語言 - ASP教程 - javascript asp教程創(chuàng)建數(shù)據(jù)庫連接

javascript asp教程創(chuàng)建數(shù)據(jù)庫連接

2019-10-22 10:20asp技術(shù)網(wǎng) ASP教程

javascript asp教程創(chuàng)建數(shù)據(jù)庫連接

While this section is devoted to ASP database utilization, it very important to remember that this web site is not intended to be a thorough ASP resource. Remember, the focus of this site is strictly limited to how to use JavaScript as your primary scripting language for ASP.

You'll see how to construct connection strings in JavaScript, use JavaScript loops to manipulate recordsets, convert the JavaScript Date Object into a format that databases can accept, and to some extent you'll see how to make SQL statements in JavaScript.

You can find a lot of good resources on database utilization. Those resources, coupled with the next four lessons, will be everything you need to write ASP JavaScript database applications.

The Connection Object:

The connection object is the link between the database and your ASP script. Remember, it's a created or instanciated object, so we can have two or more instances of Connection on one page. Connection has eight (8) methods, eleven (11) properties, nine (9) events, and finally it has two (2) properties. We will discuss three of the methods, one of the properties, and then we will forego the rest.

There are four common connections. 1) MDL 2) DSN 3) ODBC 4) OLE-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 recommends it. ODBC is better, but it's not the best. The recommended connection type is OLE-DB. That's the type of connection you'll see demonstrated below.

Get Started:

Below is the script for Lesson 16. Don't try to understand it yet. We will slowly pick this thing apart 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 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 myConnectas an argument in the Open() method.

Managing the Connection:

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();

Next Up:

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.

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 国产欧美日韩精品一区二区三区 | 成人无高清96免费 | 黑人巨大爆粗亚裔女人 | 亚洲午夜大片 | 蜜桃影像传媒破解版 | 操到翻白眼 | 青青青青青国产费线在线观看 | 国产成人精品一区 | 欧美精品黑人巨大在线播放 | 免费日批 | 国产真实伦对白在线播放 | 456亚洲人成高清在线 | 亚洲国产在线综合018 | 亚洲免费视频在线 | 西野翔全部作品在线观看 | 欧美人shou交在线播放 | 亚洲高清中文字幕精品不卡 | 视频免费视频观看网站 | 欧美1区 | 久久伊人久久 | 日本mature乱子视频 | 国产一二在线观看视频网站 | 魔兽官方小说 | 精品欧美一区二区三区四区 | 日本成人免费在线视频 | 亚洲福利一区二区精品秒拍 | 欧洲久久 | 精品国产一级在线观看 | 亚洲精品色婷婷在线影院麻豆 | 探花国产 | 朝鲜女人性猛交 | 精品播放 | 日本高清在线播放 | 欧美日韩在线成人看片a | 明星乱亚洲 | 欧美精品一线二线大片 | 成人a级特黄毛片 | 亚洲欧美一区二区三区不卡 | 特黄特级毛片免费视 | 好看华人华人经典play | 91东航翘臀女神在线播放 |