javascript asp싱넋눼쉔鑒앴욋젯쌈

2018-09-06 11:23

阅读:682

  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.

  Youll 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 youll 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, its 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. Dont use it. Also, please dont use a DSN; its slow and outdated and nobody recommends it. ODBC is better, but its not the best. The recommended connection type is OLE-DB. Thats the type of connection youll see demonstrated below.

  Get Started:

  Below is the script for Lesson 16. Dont try to understand it yet. We will slowly pick this thing apart down below.

  Click Hereto 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. Lets 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, lets 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 wont revisit them here. Down below youll see that we use myConnect as 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.

  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. Well repeat the same script in lesson 17 and go over most of what we left out the first time through.


评论


亲,登录后才可以留言!