Asp web page creation tutorial notes

Source: Internet
Author: User
Tags mdb database servervariables

Asp web page creation tutorial. Edited by Wang guorong, people's post and telecommunications Publishing House.

To open an mdb database, define an openmdb subprogram and call it in the main program.
<%
Option explicit
Sub openmdb (dbname, PWD, Conn)
'Dbname-relative path of the database file, PWD-password of the database file, And Conn-user-defined connection object.
'The PWD value can be arbitrary for databases without a password.
Dim connstr
Set conn = server. Createobject ("ADODB. Connection ")
Connstr = "provider = Microsoft. Jet. oledb.4.0;" 'specifies the ole db driver.
Connstr = connstr & "Data Source =" & server. mappath ("" & dbname & "") 'specifies the data source
Connstr = connstr & "; Jet oledb: Database Password =" & pwd' specifies the password
Conn. Open connstr
End sub

Dim Conn, RS
Call openmdb ("vote. mdb", "111", Conn)
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open "select * From vote", Conn, 2, 2
%>

-----------------------------------------------------------------------
When connecting to a database, if Microsoft provides an ole db driver, you can directly use it, such as access. If not, you need to use your own ODBC driver, such as FoxPro. Different drivers may have specific parameters.
IIS/PWS 4.0 can only access databases before Access97, but not Access2000 databases.
Microsoft claims that the execution efficiency of the ole db driver is better than that of the ODBC driver.

-----------------------------------------------------------------------
Cookies are the information recorded in the browser, while the information of other ASP objects is stored on the server. Therefore, only when the browser begins to browse a web page of the server, before the server downloads any data to the browser, the browser can exchange cookie data with the server. The solution is to write data to the buffer zone first.
In the cookie lifecycle, the session disappears only when the browser is closed, and the session may disappear even when the browser is opened due to the timeout setting. Therefore, it is better to use cookie objects to store stage data for webpages that need to be divided into various stages for input than session objects.
Browser cookies of different companies are incompatible with each other.
IE cookies are stored in the/Windows/cookies/folder.
How to set the cookie lifecycle:
Response. Cookie ("userid") = "comehope": Response. Cookie ("userid"). expires = "2008/12/31"

-----------------------------------------------------------------------
Call your own link on the webpage:
<% Myself = request. servervariables ("path_info") %>
<A href = "<% = myself %>? Page = 1 "> page 1 </a>

-----------------------------------------------------------------------
Server Object Overview
Attribute:
The maximum time for the scriptimeout server to continuously process scripts. The default value is 90 seconds.
Method:
Creatobject creates an object instance
Excute calls and executes another ASP script
Getlasterror: Create an ASP error object with an error
Htmlencode encodes HTML strings. You can use this method to display HTML source code.
Mappath specifies the physical path. When opening a file or database, ASP requires that the physical path of the file be specified. This method does not support relative directory identifiers "." and ".".
Transfer redirects to another script. The value of the request object and other objects from the first script can be used in the second script.
URL Encoding

-----------------------------------------------------------------------
Delete record statement Rs. Delete
Because the delete method deletes the current record, after the delete method is called, the current data record does not exist. We must call another method to remove the pointer from this record to continue other operations.

-----------------------------------------------------------------------
Update data records: First Change the field value and then call the update method, for example:
RS ("closing price") = 30.5
RS ("transaction volume") = 3589
Rs. Update
If the pointer is removed from the current record before the update method is called, ADO automatically calls the update method.
Array update method: Rs. Update field name array, field value array. For example:
Fieldname = array ("closing price", "transaction volume ")
Fieldvalues = array (30.5, 3589)
Rs. Update fieldname, fieldvalues
After the field value is changed and the update method is not called, The cancelupdate method is called to cancel the updated data.

-----------------------------------------------------------------------
The method for adding a record is similar to the method for modifying the record. The difference is that a buffer is created using the addnew method before this, and the system automatically sets this record as the current record, then, modify the content of the new record, just like the modification record. For example:
Rs. addnew
RS ("closing price") = 30.5
RS ("transaction volume") = 3589
Rs. Update
Add record using array method: Rs. addnew field name array, field value array.

-----------------------------------------------------------------------
Multiple SQL select statements
Select field list from table
Select field name as Alias from table
Select field name calculation result as Alias from table
Select * from Table order by field list [DESC]
Note: The field name after order by cannot be an alias. The following statement is incorrect;
Select student ID, total score of Chinese + mathematics as from transcript order by total score
Select top 10 * From transcript
Select * from table where condition expression
Select * from table where name like 'wang % '"%" represents 0-15 characters
Select * from table where name like 'wang _ '"_" represents a character
Select * from table where between value 1 and value 2
Select * from table where field name in (value 1, value 2 ,...)

If an Access database is used, the VB Function can also be used in the where condition, for example;
Select * From transcript where mid (name, 2, 1) = "large"
Select a record with the second word in the Name field equal to "large"

Use variables in the where expression;
Numeric variable; SQL = "select * from stock statement where closing price>" & VV
Date and time; SQL = "select * from sales record where sales date = #" & VV &"#"
String: SQL = "select * from stock statement where stock code = '" & VV &"'"

-----------------------------------------------------------------------
If you want to retain the content of an array element when redefining an array, you must add preserve reserved words before the array name. For example:
Redim X (5)
X (0) = 10: X (1) = 20
Redim preserve X (10)

-----------------------------------------------------------------------
Response object Overview
Attribute:
Whether the buffer writes data to the buffer first.
Contenttype defines the data type to be sent in the response body. the user's browser uses this information to determine how to compile the downloaded HTTP Response content.
Isclientconnected read-only attribute. Based on the last use of response. Write, determine whether the user is still connected to the server.
Set:
Cookie
Method:
Binarywrite writes binary data to the client.
Clear clears the buffer.
End ends the Browser Download.
Flush output buffer data.
Redirect is redirected to another URL.
Write writes information to the HTTP response.

-----------------------------------------------------------------------
Generally, the testing statement that displays intermediate results is mixed in the debugging program. However, this test is normal and it is not guaranteed that there will be no problems in the future. This time, the test statement will be removed, write it back during the next test. To avoid this situation, you can use the buffer zone to solve the problem as follows:
Response. Buffer = true
''''' Normal program
Response. Flush output the results of the previous program running.
''' Here is the test statement.
Response. clear' to output the above test results, you only need to set this sentence as a comment.

-----------------------------------------------------------------------
Application Object Overview
Set:
Contents contains all application-level variables and objects. It has two methods: contents. Remove and contents. removeall, respectively deleting one and all variables.
Method:
Lock/unlock lock the application object.
Event:
Onstart/onend is triggered when the application starts and ends.

-----------------------------------------------------------------------
The Session object must be used in combination with the cookie function of the browser. Ie4.x allows users to disable cookies, whereas ie5 and later versions do not allow users to disable cookies.
Session Object Summary
Attribute:
Sessionid uniquely identifies the read-only attribute value of each current user session.
Set:
Contents contains the variables and objects of all user session-level scopes. It has two methods: contents. Remove and contents. removeall, respectively deleting one and all variables.
Event:
Onstart/onend is triggered at the beginning and end of a user session.

-----------------------------------------------------------------------
The following program reads all the content of recordset.
<%
Dim I, row

'Part I outputs "header name"
Response. Write "<Table border = 1> <tr>"
For I = 0 to Rs. Fields. Count-1
Response. Write "<TD>" & RS (I). Name & "</TD>"
Next
Response. Write "</tr>"

'Part II outputs the "content" of the data table"
Rs. movefirst Move the current data record to the first item
While not Rs. EOF 'determines whether the last item has passed
Row = "<tr>"
For I = 0 to Rs. Fields. Count-1
Row = row & "<TD>" & RS (I) & "</TD>"
Next
Response. Write row & "</tr>"
Rs. movenext 'Move to the next item
Wend
Response. Write "</table>"
%>

-----------------------------------------------------------------------
For VBScript, the simplest input method is the inputbox function, and the simplest output method is the msgbox function. However, when writing ASP, inputbox and msgbox functions are unavailable, because ASP is executed on the server, and the user is on a remote machine, the window displayed on the server (both inputbox and msgbox functions display the window) cannot be seen by the netsher, therefore, it is meaningless to use inputbox and msgbox in ASP to input and output data.

You must use the "View Source File" function to view the data transmitted to the browser.

VBScript requires that double quotation marks in a string should be expressed with two double quotation marks. For example, the output result of response. Write "BC" "XY" is BC "XY.

It is recommended that the hidden field <input type = hidden> in the form be fixed before all the <input> labels that can be displayed.

The request object supports multiple sets. When you use a statement such as request ("name") to read information, ASP searches each set of the request object in the following order: querystring, form, cookie, clientcertificate, servervariables.

When no data exists, the returned values of the Application Object and Session object are empty (note, not null), while the request. cookies return "" (Null String), while in vbs, "Null String" cannot be computed together with a value.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.