Using ASP technology to develop database retrieval program based on www

Source: Internet
Author: User
Tags building windows count dsn odbc
Program | data | Database ASP is a new technology introduced by Microsoft to replace CGI, and is now recognized as the best tool for building Windows NT dynamic sites. With the full combination of ADO (Active data Object, a new data access model), it provides a powerful database access function, which makes it an important means for online database management.

First, ASP Introduction

ASP is embedded in the Internet Information Server (IIS3.0), with an. asp extension. ASP files can be edited using a regular text editor, but also the use of specialized auxiliary development Tools InterDev for development and design, InterDev is the advantage of the entire Web programming (including Web design, ASP program design, database management, etc.) into one, More suitable for the development and development of larger projects. ASP uses scripting languages such as VBScript, JavaScript as a development tool, embedded in HTML text, and uses "<%...%>" to include ASP's programs. When a user makes a request from a browser to a Web server, the Web server automatically interprets the ASP's program as a standard HTML-formatted home page, and the client can browse the content of the home page that is designed by the ASP by using a browser that is normally executable HTML, so it has nothing to do with the browser. and to ensure that the ASP's source code does not leak out.

The ASP includes five built-in ActiveX server components and five built-in objects: Database access component, file access component (Files accessing component), Ad rotator Component (Advertisement Carousel component), Content Linking component (contents link component), Browser capabilities component (Browser letter component), and request (requesting object), Servers (server objects), sessions (Session objects), Response (response objects), application (Application objects). Among all ASP components, the most useful is the database access component, also known as an ActiveX Data object or ADO. This component and the objects contained in it will be used in the site publishing database to complete reading and writing to the ODBC data source.

In addition, another important feature of ASP technology is that programmers can make use of Java, Visual Basic, Visual C + +, and other languages to adapt to their special needs of the ActiveX server components to expand the functionality of the ASP, so that their dynamic web pages have almost unlimited capacity to expand, This is not the traditional CGI program.

Development of database retrieval program based on WWW in combination with ADO

ASP technology combined with ADO technology, can realize the database management function based on WWW, the user can retrieve, input, update and delete the database information in the browser screen, thus establish the homepage content that provides the database information. ADO mainly provides seven objects and four sets to manage the database, including: Connection, Command, Parameter, Recordset, Field, property, error, and fields, Properties , Parameters, Errors. The connection object is used to establish a connection to the database, and the command object completes operations on the database, which can view or manipulate the data returned in the database. The Field object and the Fields collection allow you to manipulate each field in the current record, and the Parameter object and the Parameters collection provide information and data for the Command object. The objects and Properties collection provides information for the attributes of the connection, Command, Recordset, Field object, and the Error object and the Errors collection provide the wrong information when the error occurs.

The following is an introduction to the basic design methods for developing database retrieval programs:

⒈ Create the database source name (DSN). DSN is a database logical name that is created by ODBC and that is used and recognized by ODBC to connect applications and background databases. The specific method of creating an ODBC data source can be found in the relevant information, which is not covered here. Suppose you have created an ODBC data source named "book" for a SQL Server database.

⒉ Create a database link (Connection). The CreateObject method of the server object enables you to create connection objects and use variables to accept object references. Once the connection object is created, it can be used to open a connection to any ODBC data source. are as follows:

Dim conn ' Declare variable

Set conn=server.creatobject ("ADODB. Connection ")" Create a linked object

Conn.Open "book", Iusr_tsg01, "" "Open the link to ODBC, where IUSR_TSG01 is the authorized user ID number, the user password is not set. Programmers should be replaced according to their own circumstances.

⒊ creates a data object (Recordset). A Recordset is a more complex object in ADO, with many properties and methods, including: Eof (end of file), Bof (file header), AbsolutePage (Absolute page), Recordcount (Record Count), Common methods such as PageCount (page count) and MoveFirst (move to first record), MoveLast (move to last record), MoveNext (move to Next record), MovePrevious (move to previous record). The data object is combined with the ASP's session object, and can also realize the paging processing of the retrieval result.

Dim Rs ' declaration variable

Set rs=server.creatobject ("ADODB. Recordset ")" To create a data object

rs.pagesize=10 ' Sets the number of records displayed on a page

⒋ operations database. ADO implements the retrieval function by executing standard SQL statements, so you first define the SQL query statement and then execute the query command, which ultimately forms a collection of retrieved results.

Dim SQL ' declare variable

Sql= "SELECT * Publication where title like ' asp%% '" "Defines the SQL query statement that retrieves the records of all books in the publication table of the database that begin with ASP

Const adopenkeyset=1 ' defines the type of the recordset

Rs.Open Sql,conn, adOpenKeyset ' executes the SQL statement, saving the retrieved results in the data Object Rs.

⒌ returns results in ASP. If you are ready to display the book information in the check in the browser, you can use the following two ways:

<% Response.Write (Rs. ("Title"))%> or

<%=rs ("Title")%>

⒍ closes database objects and linked objects. Be sure to close the ADO object before the program ends and release the server resources. As follows:

Rs.close

Conn.close

Set rs=nothing

Set conn=nothing

Here is an extremely simple search program that will help you understand some of the concepts.

Example.asp



<title>asp Database Retrieval Example </title>


<%

Dim Conn

Set Conn = Server.CreateObject ("ADODB. Connection ")

Conn.Open "book"

Sql= "SELECT * from publication where title like ' asp%% '"

Dim Rs

Set rs=server.createobject ("Adodb.recordset")

Const adopenkeyset=1

Rs.Open Sql,conn, adOpenKeyset

%>

<strong> Search word hit rate:<%=rs.recordcount%><br><br>

<select size=8>

<%

Do as not rs.eof

%>

<option><% =rs ("title")%></option>

<%

Rs.movenext

Loop

%>

</select>

<%

Rs.close

Conn.close

Set rs=nothing

Set conn=nothing

%>

</body>


I use ASP technology to develop the Yantai University Library online Bibliographic Retrieval program, the practice proved that this method is simple, practical and efficient, is a very worthy of learning a method.



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.