Database ASP Solution for Personal homepage

Source: Internet
Author: User

Now that CGI is fading, the ASP is on its way to replace it. CGI is also really too complicated for a personal homepage author, especially in database operations, which is incredibly complex and daunting. ASP, by contrast, is much simpler. Its object-oriented thinking hides the complex underlying operation, leaving only a simple calling interface. The operation of the database is the embodiment of its merits incisively and vividly.

This article will briefly introduce the use of ASP in the personal home page to connect the database to achieve dynamic Web pages. After reading this article, I believe your homepage will be more exciting.

1. Querying an Access database in ASP

ASP allows us to query and update the database in a simple way. The following examples are given in MS ACCESS database, but the rationale for doing so can be applied equally to any ODBC-enabled database. (Access is chosen because it is easy to operate and widely used, and access is undoubtedly the best choice for most small and medium projects.) )

First use access to create a datasheet as follows:

User number Name City Phone number
1 Tom Wuhan 027-84713858
2 John doe Beijing 010-99581426
3 Harry Shanghai 021-85541253

Again, take a look at the following example:

<%
SET DBCONNECTION=SERVER.CREATEOBJECT (“ADODB.CONNECTION”)
DBCONNECTION.OPEN “DSNNAME”
SQLQUERY=“SELECT * FROM CUSTOMERS”
SET RECUSTIONMERLIST=DBCONNECTION.EXECUTE (SQLQUERY)
%>
< CENTER>
< TABLE BORDER=1>
< % DO WHILE NOT RECUSTOMERLIST.EOF %>
< TR>
< TD><% =RECUSTOMERLIST(“客户编号”)%>< /TD>
< TD><% =RECUSTOMERLIST(“姓名”)%>< /TD>
< TD><% =RECUSTOMERLIST(“城市”)%>< /TD>
< TD><% =RECUSTOMERLIST(“电话号码”)%>< /TD>
< /TR>
< % RECUSTOMERLIST.MOVNEXT LOOP %>
< /TABLE>
< /CENTER > 

You can see that the ASP's syntax is VBScript, and its object-oriented thinking is similar to VB, so, as long as you first pass VB or VBScript, that ASP can easily on the ground hand.

Part of the above can be said to be the essence of ADO in ASP, we discuss the content of the code "% and%> is the beginning and end of ASP code." When the server returns a user request, it interprets the contents of <% and% as standard HTML code and sends it to the client browser. When you access a database, you first establish a connection, that is, declare an instance of a connection class (object), and then use the Open method of the connection class to connect the connection object to an ODBC data source, in the example DSNname, which is a DSN. As for what is DSN, the following will be introduced, and first press not the table. To this end, the database connection has been completed, the following is the operation of the database.

The operation is also simple, defining an SQL statement string, and then invoking the execution of the connection Execute method, which is stored in the object of a recordset class (which can be viewed as a table that temporarily holds data), in the example of Recustomerlist. In this way, the database query call is completed, and then simply output it.

In doing while ... When the loop is output, the write method of the Respond object in the ASP is invoked, which can generally be abbreviated to "=". The Statement recustomerlist (field name) returns the value of the corresponding field in the current record. The last call is the MoveNext method of the recordset class, which moves the record pointer to the next record, and executes repeatedly until the recustomerlist EOF (end of file) is true. In this way, the returned query results are exported.

This is just a little bit of basic knowledge of ASP data access, but we can get a glimpse of the powerful capabilities of ASP.

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.