ASP access to databases

Source: Internet
Author: User

Wen/Wang hanzhou

ASP is the Active Server Page. It is a dynamic Web Design Technology launched by Microsoft. It is a server-side scripting environment for WWW services. It explains scripts on the Web server of the site, dynamic, interactive, and efficient website server applications can be generated and executed.Program.

Overview



With ASP, we can easily combine HTML (Hypertext Markup Language) text, script commands, and ActiveX components to form ASP pages to generate dynamic web pages, create an interactive web site to access the Web database. When a user requests an ASP homepage through a browser, the web server responds, calls the ASP engine to execute ASP files, explains the script language (jscript or VBScript), and connects to the database through ODBC, the database access component ADO (ActiveX Data Objects) completes database operations. Finally, ASP generates an HTML homepage containing data query results and returns it to the user end.

Because ASP runs on the server, the running result is returned to the user's browser in the form of an HTML homepage. What you see in the client browser is only the page generated by the execution result of the ASP page, the content of the ASP page is invisible to users in the client browser, which increases the security and confidentiality of the system. In addition, ASP is an object-oriented scripting environment. Users can add ActiveX components to expand their functions and expand their application scope.

ASP database access procedure

In ASP, you can use the following steps to access a web database:

1. Define data sources

Open "Control Panel" on the Web server, select "ODBC", select "add" under "system DSN", and select the desired database type, name, and location. This document defines "SQL Server", the data source is "ht", the database name is "htdata", and the script language uses JScript.

2. Use the ADO component to query web databases

1) call server. Createobject to obtain the "ADODB. Connection" instance, and then open the database using the open method:

Conn = server. Createobject ("ADODB. Connection ")

Conn. Open ("ht ")

2) Specify the SQL command to be executed

After connecting to the database, you can perform operations on the database, such as querying, modifying, and deleting. These operations are completed using SQL commands, such as querying in the signaltab of the data table.CodeRecords containing "X:

Sqlstr = "select * From signaltabswherescode like '% x % '"

Rs = conn. Execute (sqlstr)

3) attributes and methods of recordset

To track data more accurately, use the recordset component to create a cursor containing data. The cursor is the data stored in the memory:

Rs = server. Createobject ("ADODB. recordset ")

Rs. Open (sqlstr, Conn, 1,)

Note: A = 1 indicates reading data; A = 3 indicates adding, modifying, or deleting data.

Common attributes and methods in the recordset component include:

Rs. Fields. Count: Number of recordset object fields.

RS (I). Name: name of the I-th field, where I is 0 to Rs. Fields. Count-1

RS (I): The data of field I, where I is 0 to Rs. Fields. Count-1

RS ("field name"): Specifies the data of a field.

Rs. Record. Count: Total number of data records.

Rs. EOF: indicates whether the last record is used.

Rs. movefirst: point to the first record.

Rs. movelast: point to the last record.

Rs. moveprev: point to the previous record.

Rs. movenext: point to the next record.

Rs. getrows: puts data into the array.

Rs. properties. Count: the number of attributes of the resultset or connection of ADO.

Rs. properties (item). Name: name of the resultset or connection of ADO.

Rs. properties: The resultset or connection value of ADO.

Rs. Close (): Close the connection.

4) shut down the database

Conn. Close ()

Instance

The following example is the development of the Web function module in the product Query System of a Technical Center. The system requires that the system return the query result when the user inputs the query information, such as the origin or product category. take the product category as an example: catachoi. ASP files use form tags to form a query entry. When you select a product category and press the "Submit" button, the product class ID is sent to p_result.asp as a prodname variable, p_result.asp use SQL statements to query database table files on the server based on the value of the prodname, and return the query results to the browser.

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.