Lesson 15th: Commonly used ASP ActiveX components

Source: Internet
Author: User
Tags count data structures implement connect odbc prev query microsoft iis
When you use ASP to write server-side applications, you must rely on ActiveX components to powerful WEB application functions, such as: you need to connect the database, the database online operation, etc., following the introduction of the AD Rotator components, this article will then introduce some other common ASP a How the Ctivex component is used.

A lot of friends have recently written to ask me whether ASP can operate on a non-NT platform only on Microsoft IIS. I've answered this question many times before: I've just heard of some kind of software that I can support, but I've never seen it. But some enthusiastic friends continue to write to ask, so in the hospitality of friends, I visited the ASP related sites, unexpectedly surprised to find that the original ASP is really can run on other non-NT platform, so at the beginning of this article, I will give a letter to the friends briefly how to use on non-NT platform Asp.

To develop and run an ASP application on a non-NT platform we can rely on a set of Third-party software called Instant ASP, its advertising slogan is very attractive "ASP anytime, Anywhere", I think all ASP developers see such slogans must be excited. The software developed by Halcyon Software company allows you to run it on any platform without duplicating the original ASP application! This saves a lot of development time and makes the ASP truly a cross-platform Internet, Intranet, or Extranet application. Instant ASP itself is actually a suite of java-based applications, so you can run a web-based ASP application on any platform, and the following table lists the operating platforms supported by the current version of Instant ASP.



More surprisingly, Instant ASP not only provides an ASP's operating environment, but also provides a more powerful and practical feature than the current ASP application on the market, which will ActiveX components and Enterprise Java Beans or Corba-complian T objects together, so that the ASP has a more extensive application. It also provides the ability to access various databases through the ADO interface and generate dynamic pages. Developers can use their own programming languages or tools such as visual Basic, JScript, VBScript, C + +, Java, HTML, Delphi, MS Visual InterDev, and so on. About Instant ASP specific installation and operation I'm not here to start, interested friends can go to its site to see halcyonsoft.com, you can download a trial version of the free try.

Following the previous article about the use of the AD Rotator component, let's take a look at some other ASP-common components today.

One, Database Access components

The most common and practical task we use with Web applications on a Web server is to access the server-side database. The database access component built into ASP allows us to easily access information stored on server-side databases or other tabular data structures through ActiveX data Objects (ADO). ADO is the most efficient and straightforward way to operate a database currently supported by Microsoft, a powerful data access programming model that allows most data source programmable properties to be extended directly to your Active Server page. You can use ADO to write compact and concise scripts to connect to Open database Connectivity (ODBC)-compliant databases and OLE DB-compliant data sources, so that ASP programmers can access any ODBC-compliant database, including MS SQL SERVER, Access, Oracle, and so on. If you are a scripting person with a certain understanding of database connections, you will find that the ADO command statements are not complex and easy to master. Similarly, if you are an experienced database programmer, you will correctly understand the advanced language-independent and query-processing capabilities of ADO. Familiar with VB database programming friends will find ADO and RDO (Remote Data Objects) have some kind of place. But ADO is said to be accessing faster and less memory.

Here's a brief introduction to using ASP's database Access component to connect to and manipulate WEB databases via ADO

The first step: Specify the database you want to connect to, with DSN and dsn-less two methods.

DSN (data source name): Establish a System data source name as follows:

1, click "Start", select the Settings Control Panel.

2, double-click the icon "32-bit ODBC", will pop up a dialog box, select the tag "System DSN"

3, click "Add" to add a DSN entry, select "Microsoft Access Drive" and confirm.

4. Enter the DSN you want to specify in the "Data Source Name" column, and click "Select" to select the database storage location, which you can select by clicking "Browse".

5, after the completion of the above steps in the ASP program to specify DSN, as follows:

<%CONNSTR = "DSN"%>

Dsn-less: Is another way to specify the location of a database file directly in an ASP file without having to establish a DSN. Since many companies do not have their own web servers, their Web sites tend to be stored on remote virtual servers, so setting up and modifying DSN settings can be tricky. Using the Dsn-less method to specify the location of the remote database directly solves the problem, as follows

:

<%
ConnStr = "dbq=" +server.mappath ("Database/source.mdb") + ";D efaultdir=;D river={microsoft Access DRIVER (*.mdb)};D Riverid=25;fil=ms Access;implicitcommitsync=yes; maxbuffersize=512; maxscanrows=8; pagetimeout=5; safetransactions=0; threads=3; Usercommitsync=yes; "
%>

After you specify the database that you want to connect to, you can connect to and open the database in the following ways:

<%
Set Conn = Server.CreateObject ("ADODB. Connection ") Conn.Open Constr
%>

Step Two: Specify the SQL instructions you want to execute, and you can use the RecordSet.

When you connect to a database, you can manipulate the database, such as queries, deletes, updates, and so on, which are done through SQL instructions, as in the following example, in the database table datebase, query all names with a record of "a":

<%
Sql= "SELECT * from datebase where name like ' a%% '"
Set rs = conn.execute (SQL)
%>

Although the Connection object simplifies the connection database and query tasks, there are still many deficiencies in the Connection object. To be exact, a Connection object that retrieves and displays database information cannot be used to create a script, and you must know exactly what changes you want to make to the database before you can use the query to implement the changes. ADO provides a Recordset object for retrieving data, checking results, and changing the database. As its name implies, the Recordset object has many features that you can use, and, depending on your query restrictions, retrieves and displays a set of database rows, that is, records. The Recordset object retains the location of the records returned by the query, allowing you to scan the results one at a time. Depending on the pointer Type property setting of the Recordset object, you can scroll and update the record. A database pointer lets you navigate to a specific item in a set of records. Pointers are also used to retrieve and check records, and then perform actions on the basis of those records. The Recordset object has properties that can be used to precisely control the behavior of the pointer and improve your ability to examine and update the results.

The Recordset is used in the following ways:

Set rs = Server.CreateObject ("ADODB.") Recordset ")

Rs. Open SQL directive, Conn, 1, 1 ' read

Or

Rs. Open SQL directive, Conn, 1, 3 ' Add, modify, or delete

Step three: Use the RecordSet properties and methods, and display the results of the execution.

With the instructions above, we created a cursor (RecordSet) "RS" containing data, in fact a cursor is something that is stored in an array of similar records and fields in active memory, and when a cursor is created through the RecordSet component, it obtains a dataset from the provider of the data, and using it to enrich the cursor, we can imagine that the recordset produced by ADO is a record like a spreadsheet, it has a row of records, and at any time a row is its current row, and the recordset's fields are represented by the recordset's field collection. Some properties and methods of the RecordSet object (cursor) that you create are listed below

:

Rs. The total number of fields for the Fields.Count:RecordSet object.

RS (i). Name: The names of the I fields, I count from 0 to Rs. Fields.count-1.

RS (i): reads the data of the first field, I from 0 to Rs. Fields.count-1.

RS ("field name"): reads the data for the specified field.

Rs. RecordCount: The total number of data records in the cursor.

Rs. EOF: Whether the last record has been indicated.

Rs. MoveNext: Moves the metric to the next record.

Rs. MovePrev: Moves the metric to the previous record.

Rs. MoveFirst: Moves the metric to the first record.

Rs. MoveLast: Moves the metric to the last record.

Rs. Close: Closing the RecordSet object

Other introduction of ADO, the author will give you detailed explanation in the future.

Ii. Content Linking components

If your site has a series of interrelated pages, the Content linking component will be perfect for your needs, not only allows you to create a table of contents in these pages, but also create dynamic connections between them, and automatically generate and update Catalog tables and previous and subsequent Web The navigation link for the page. This is an ideal choice for listing online newspapers, electronic reading sites, and forum mail.

The content Linking component creates a Nextlink object that manages the URL list, and to use the content Linking component, you must first create the content Linking List file. The Content linking component is reading this file to get information about all the pages we want to link to. In fact, the file is a plain text file with the following contents:
Page1.htm One
Page2.htm Two
Page3.htm Three
Page4.htm Four
Page5.htm Five
Page6.htm Six

Each line of this text file has the following form:

URL description Comment

Where URLs are hyperlinks to pages, description provides textual information that can be used by hyperlinks, and comment contains annotation information that is not interpreted by the Content linking component, which acts as a comment in a program. The description and comment parameters are optional.

Let's take a look at how to use the Content linking component specifically:

< html>
< head>
< meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
< title> network Electronic books Treasure </title>
< body>
< p> network Electronic reading Navigation
<%
Set Link = Server.CreateObject ("MSWC.") Nextlink ")
Count = Link.getlistcount ("Nextlink.txt")
Dim I
For I=1 to Count
%>
< ul>< li>< a href= "<%= link.getnthurl (" Nextlink.txt ", I)%>" ><%= link.getnthdescription (" Nextlink.txt ", I)%></a>
<% Next%>
</body>

In the above code, we first use the GetListCount method to determine how many items are in the file Nextlink.txt, and then use the Loop statement, and use the GetNthURL, GetNthDescription method to store each one in the Nextlink.txt The contents of the file are read out and displayed to the client browser.

The following lists the number of items linked in the GetListCount (file) Statistics content link list file for all available methods of the content linking component.

GetNextURL (file) Gets the URL of the next page listed in the Content Link list file.

GetPreviousDescription (file) Gets the description line for the previous page listed in the Content Link list file.

GetListIndex (file) Gets the index of the current page in the Content Link list file.

GetNthDescription (File,index) Gets the description of the nth page listed in the Content Link list file.

Getpreviousur (file) Gets the URL of the previous page listed in the Content Link list file.

GetNextDescription (file) Gets the description of the next page listed in the Content Link list file.

GetNthURL (File,index) Gets the description of the nth page listed in the Content Link list file.

After we created the site's total navigation page, we certainly want to add a "prev", "Next" Navigation hyperlink on each page, let's look at how to implement the navigation chain.

Since your site may contain thousands or more pages, it is not possible to write ASP code that implements the navigation hyperlink in every page. So we have to take advantage of the server-side containment SSI we learned in the previous few, so that we avoid a lot of duplicate jobs, see the following example:

<!--#include file= "Nextprev.inc"-->

Just place the end of the code on each page. The contents of the Nextprev.inc file are as follows:

<%
Set Link = Server.CreateObject ("MSWC.") Nextlink ")
Count = Link.getlistcount ("Nextlink.txt")
Current = link. GetListIndex ("Nextlink.txt")
If Current > 1 Then
%>
< a href= "<%= link.getpreviousurl (" Nextlink.txt ")%>" > Prev </a>
<%
End If
If Current < Count Then
%>
< a href= "<%= link.getnexturl (" Nextlink.txt ")%>" > Next </a>
<% end If%>

Today's study is over, and here I want to thank all the friends who care about my article again, your letter gave me great encouragement, but please do not call me "teacher", in fact, I also and you are in constant learning and groping, there are problems we can discuss together, I am sure there are a lot of deficiencies or loopholes in my article, and I hope that you will be able to put forward to me in time. Since the recent ASP has been widely used in the domestic web site, so at the request of friends, in the domestic ASP Master Bird's enthusiastic help, I decided to write some examples of ASP application as now the sister of this article, so that you can provide some really practical things, please pay attention to.



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.