Notes | tutorials | Web pages
"ASP Web page production tutorial." Wangguorong, People's post and telecommunications press.
How to open an MDB database: First define a Openmdb subroutine, and then call in the main program.
<%
Option Explicit
Sub Openmdb (Dbname,pwd,conn)
' Dbname-the relative path of the database file, pwd-the password of the database file, conn-the user-defined Connection object.
' For databases without passwords, the PWD value can be arbitrary.
Dim connstr
Set conn = Server.CreateObject ("ADODB. Connection ")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;" ' Specify an OLE DB driver
CONNSTR=CONNSTR & "Data source=" & Server.MapPath ("" &dbname& ")" Specify the source
Connstr=connstr & "; Jet oledb:database password= "& pwd" Specify password
Conn. Open ConnStr
End Sub
Dim Conn,rs
Call Openmdb ("Vote.mdb", "the", "Conn")
Set rs=server.createobject ("ADODB. Recordset ")
Rs.Open "SELECT * from vote", conn,2,2
%>
-----------------------------------------------------------------------
When you connect to a database, if Microsoft provides an OLE DB driver, use it directly, such as access. If not provided, you need the database's own ODBC driver, such as FoxPro. For different drivers, there may be specific parameters for them.
IIS/PWS 4 can only access Access97 previous databases, but not access Access2000 databases.
Microsoft claims that OLE DB drivers perform better than ODBC drivers.
-----------------------------------------------------------------------
Cookies are recorded in the browser information, while other ASP object information is stored on the server side, so only when the browser starts browsing a server's Web page, and the server has not downloaded any data to the browser, The browser can exchange cookies data with the server. The solution is to write the data to the buffer first.
Because in the cookie lifecycle, only close the browser will disappear, and session because of the timeout settings, even if the browser open, midway may disappear. Therefore, for pages that need to be entered into each phase of the data, using a cookie object to hold the phased data is more appropriate than the session object.
Browser cookies from different companies are incompatible with each other.
The IE cookies are stored in the \windows\cookies\ folder.
How the cookie lifecycle is set:
Response.cookie ("UserID") = "Comehope": Response.cookie ("UserID"). expires= "2008/12/31"
-----------------------------------------------------------------------
Call your own link in the Web page:
<% myself=request.servervariables ("Path_info")%>
<a href= "<% =myself%>?page=1" > first page </A>
-----------------------------------------------------------------------
Server Object Overview
Property:
The maximum time the Scriptimeout server continues to process the script, default is 90 seconds.
Method:
Creatobject create an instance of an object
Excute invoke and execute another ASP script
GetLastError to establish an ASP Error object that occurred
HTMLEncode HTML strings, you can use this method to display HTML source code
MAPPATH specifies the physical path. Because when you open a file or database, the ASP specifies that the physical path to the file must be specified, and the method does not support relative directory identifiers "." and ".."
Transfer Redirect to another script, the request object from the first script and the values of other objects can be used for the second script.
UrlEncode the address to encode
-----------------------------------------------------------------------
Delete a record statement rs.delete
Because the Delete method deletes the current record, the current data record will not exist after the Delete method is called, and we must call a method to move the pointer away from this record before proceeding to another operation.
-----------------------------------------------------------------------
Update data records: First change the field value, and then call the Update method, such as:
RS ("closing price") =30.5
RS ("turnover") =3589
Rs.update
If the pointer moves away from the current record before the Update method is called, ADO automatically calls the Update method.
Methods for updating using arrays: rs.update array of field names, array of field values. Such as:
Fieldname=array ("Closing price", "turnover")
Fieldvalues=array (30.5,3589)
Rs.update fieldname,fieldvalues
Calling the CancelUpdate method cancels the updated data after changing the value of the field without calling the Update method.
-----------------------------------------------------------------------
The method of adding a record is similar in that the method of modifying a record is different by creating a buffer by using the AddNew method, which automatically sets the record to the current record and then modifies the contents of the new record as if it were a record. Such as:
Rs.addnew
RS ("closing price") =30.5
RS ("turnover") =3589
Rs.update
To add a record method using an array: An array of rs.addnew field names, an array of field values.
-----------------------------------------------------------------------
Multiple forms of SQL SELECT statements
Select field List from table
Select field name as Alias from table
Select field name operation result as alias from table
SELECT * FROM table order by field list [desc]
Note: The field name after the order by cannot be an alias, as the following statement is incorrect;
Select number, Chinese + math as total score from transcript order by total score
Select Top * FROM transcript
SELECT * FROM table where condition expression
SELECT * FROM table where name like ' King% ' "%" stands for 0-15 characters
SELECT * FROM table where name like ' King _ ' ' _ ' 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 you use an Access database, the VB function can also be used in a where condition, such as;
SELECT * from transcript where mid (name, 2, 1) = "Big"
Select the Last Name field the second word equals "big" record
Use variables in the where expression;
numeric variable; sql= "SELECT * from stock quotes where close >" & VV
Date time; sql= "SELECT * from transaction record where buy and sell date =#" & VV & "#"
String: sql= "SELECT * from stock quotes where stock tickers = '" & VV & "'"
-----------------------------------------------------------------------
If you want to preserve the contents of an array element when you redefine the array, precede the array name with preserve reserved words, such as:
ReDim x (5)
X (0) =10:x (1) =20
ReDim Preserve x (10)
-----------------------------------------------------------------------
Response Object Overview
Property:
Whether the buffer writes the data to the buffer first.
ContentType defines the type of data to send in the response body, which the user's browser uses to determine how to compile the downloaded HTTP response content.
IsClientConnected read-only property that determines whether a user is still connected to the server, based on the most recent use of Response.Write.
Collection:
Cookies
Method:
BinaryWrite writes binary data to the client.
Clear clears buffer buffer.
End Browser Download.
Flush output buffer data.
Redirect Redirect to another URL.
Write writes information to an HTTP response.
-----------------------------------------------------------------------
Generally in the debugger will be mixed with the intermediate results of the test statements, but this time the test does not guarantee that there will be no problems, this time to remove the test statements, the next test to write back, in order to avoid this situation, you can use the buffer to solve, as follows:
Response.buffer=true
"" The normal procedure
Response.Flush outputs the results of previous programs running.
"" Here is the test statement
Response.Clear ' to output the above test results simply set this sentence as a comment