ASP Basics Tutorial: Common ASP ActiveX components

Source: Internet
Author: User
Tags dsn web database microsoft iis

When you use ASP to write server-side applications, you must rely on ActiveX components to powerful WEB application features, such as: you need to connect to the database, the database online operation, and so on, following the introduction of the AD Rotator component, this article will then introduce some other common ASP a How to use the Ctivex component.

Many friends have recently written to ask me whether ASP can only be run on Microsoft IIS and whether it works on a non-NT platform? I have answered this question many times: I have only heard of some kind of software that can be supported, but I have never seen it. But some enthusiastic friends are still tireless letter to inquire, so in the hospitality of friends, I visited the ASP related sites, unexpectedly surprised to find that the original ASP can be run on other non-NT platform, so at the beginning of this article, I will give a brief introduction to the letter to friends how to use the non-NT platform Asp.

To develop and run ASP applications on non-NT platforms we can rely on a set of third-party software called Instant ASP, which is very appealing to "ASP Anytime, Anywhere," and I think all the ASP developers will be excited to see such slogans. This software developed by Halcyon Software allows you to run it on any operating platform without having to re-develop an existing 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 set of Java-based applications, so through which you can run WEB-based ASP applications on any platform, the following table lists the operating platforms supported by the current version of Instant ASP.

Even more surprising is that Instant ASP not only provides the operating environment of ASP, but also provides a more powerful and practical function than the current ASP application on the market, it will ActiveX components and Enterprise Java Beans or Corba-complian T objects is combined to make the ASP more widely used. It also provides the power to access various databases and generate dynamic pages through the ADO interface. Developers can use their own programming language or tools such as: Visual Basic, JScript, VBScript, C + +, Java, HTML, Delphi, MS Visual InterDev, and so on. About Instant ASP installation and operation I am not here to expand, interested friends can go to its site to see halcyonsoft.com, you can also download a free trial version to try. Shanghai Treatment Impotence Hospital}

Following the author's introduction to the use of AD rotator components, let's look at some of the other ASP's common components today.


I. Database Access component
The most common and practical task we use with Web applications on a Web server is to access the server-side database. The built-in database access component of ASP makes it easy to 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 of the data source programmable properties to be extended directly to your Active Server page. You can use ADO to write compact, concise scripts to connect to Open database Connectivity (ODBC)-compliant databases and OLE DB-compatible data sources so that ASP programmers can access any ODBC-compliant database, including MS SQL SERVER, Access, Oracle, and more. If you are a scripting person with a certain understanding of database connections, you will find that ADO command statements are not complex and easy to master. Similarly, if you are an experienced database programmer, you will know the advanced language independence and query processing capabilities of ADO correctly. Familiar with VB database programming friends will find that ADO and RDO (Remote Data Objects) have some kind of a similar place. However, it is said that ADO accesses faster and requires less memory.

Here is a brief introduction to the database access component using ASP to connect and manipulate the WEB database through 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" to select the settings Control Panel.

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

3. Click ' Add ' to add a DSN entry, select such as "Microsoft Access Drive" and confirm.

4. Enter the DSN you want to specify in the "Data Source Name" field and click "Select" To choose the database
Storage location, you can click "Browse" to select.

5. After completing the above steps, specify the DSN in the ASP program 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
Method. Because many companies do not have their own web servers, their sites are often stored on remote virtual servers, so
Setting up and modifying DSN settings is tricky. Using the Dsn-less method to directly specify where the remote database is located solves the
This problem, the method is as follows:

<%
ConnStr = "dbq=" +server.mappath ("Database/source.mdb") + ";
defaultdir=;D river={microsoftaccessdriver (*.mdb)};
driverid=25;fil=msaccess;
Implicitcommitsync=yes;
maxbuffersize=512;
maxscanrows=8;
pagetimeout=5;
safetransactions=0;
threads=3;
Usercommitsync=yes; "
%>

Once you have specified the database you want to connect to, you can connect 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 the database is connected to the database can operate, such as query, delete, update and so on, these operations are done by SQL instructions, the following example in the database table Datebase query all names have "a" record:

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

Although the Connection object simplifies connection to the database and query tasks, there are still many deficiencies in the Connection object. Specifically, the 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 the results, and changing the database. As its name implies, the Recordset object has many features that you can use to retrieve and display a set of database rows, or records, based on your query constraints. The Recordset object keeps 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 examine records, and then perform operations on the basis of those records. The Recordset object has properties that can be used to precisely control the behavior of pointers, increasing your ability to examine and update results.

The Recordset is used in the following ways:

Set rs = Server.CreateObject ("ADODB". Recordset ")
Rs. Open SQL instruction, Conn, 1, 1 \ ' Read

or

Rs. Open SQL instruction, Conn, 1, 3 \ ' new, modified, or deleted

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

Using the instructions above, we create a cursor (RecordSet) "RS" that contains 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 from the RecordSet component, it gets a dataset from the data provider, and using it to enrich the cursor, we can imagine that the recordset generated by ADO is a spreadsheet-like record with a row of records, at any time a row is its current row, and the recordset field is represented by the recordset's Fields collection. The following is a list of the properties and methods of the RecordSet object (cursor) created:

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

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

RS (i): reads the data from the I field, I count 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 referred to.

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

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

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

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

Rs. Close: Closing the RecordSet object

For other introduction of ADO, the author will give you a detailed explanation in the future.

Ii. Content Linking components

If your site has a series of interrelated pages, the Content linking component will be a great fit for your needs, not only to enable you to create a table of contents in these pages, but also to establish dynamic connections among them and to automatically generate and update Catalog tables and previous and subsequent Web The navigation link for the page. This is ideal for listing online newspapers, e-readers, and forum Mail.

The content Linking component creates a Nextlink object that manages the list of URLs, and to use the content Linking component, you must first create a content Linking List file. The Content linking component is just 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
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 the URL is the hyperlink address associated with the page, description provides the text information that can be used by the hyperlink, comment contains not be Content linking a delicacy steal Nao ⑹ side Ⅲ Nao shinny Meng bin sash painted weapon nao ⑹ ting? Description and Comment Ginseng The number is 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 E-Books Treasures </title>

< body>
< p> network e-reader 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, then use the Loop statement, and use the GetNthURL, GetNthDescription method to store the The contents of the Nextlink.txt file are read out and displayed to the client browser.

The following is a list of all the available methods of the content Linking component GetListCount (file) Statistics the number of items linked in the Content Link list file.

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 page N 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 a description of the next page listed in the Content Link list file.

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

After we have created the total navigation page of our website, we would certainly like to add a "previous page", "next page" navigation hyperlink on each page, let's look at how to implement the navigation hyperlink.

Given that your site may contain thousands or more pages, it is not possible to write ASP code that implements navigation hyperlinks on every page. Therefore, we must take advantage of the server-side inclusive SSI we learned in the previous few, thus avoiding a lot of repetitive tasks, see the following example:

<!--#include file= "Nextprev.inc"-
  
Just put this side 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 ")%>" > Previous </a>
<%
End If
If Current < count Then
%>
< a href= "<%= link.getnexturl (" Nextlink.txt ")%>" > Next </a>
<% End If%>
  

Today's study is over again, here I would like to thank all the friends who care about my article, your letter to
I am greatly encouraged, but please do not call me "teacher", in fact, I also like you are in constant learning and groping,
There are problems we can discuss together, my article is certainly still a lot of shortcomings or loopholes, but also hope that we can find out in time to my
Proposed Since the recent ASP has been widely used in the domestic web site, so the request of friends, in the domestic ASP master
With the enthusiastic help of Asuka, I decided to write some examples of ASP application as a sister article in this article, so that we can
Provide some really useful things, please pay attention.

ASP Basics Tutorial: Common ASP ActiveX components

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.