embedding and calling ActiveX controls in ASP

Source: Internet
Author: User
Tags define sql ole rollback variable access database access
Active|activex| control |activex| controls have a large number of people who understand ASP (Active Server Pages), but few people can easily invoke ActiveX controls with ASP; If you do not invoke an ActiveX control, It can be said that Microsoft originally designed ASP's original intention has not been achieved. As we all know, ActiveX technology is another new initiative of Microsoft in addition to IE on the internet, it can be said that the technology permeates its entire Internet policy. ActiveX is a powerful part, you can use VB, C or C + + language to write, because it is a compilation of implementation, so the speed is relatively fast. There are several powerful ActiveX Server controls built into the ASP (active Server Pages), including Ad Rotator (dynamic ad generation control), BrowserType capabilities (browser compatible control), DB Access (Database access control), Content linking (file link control), and file access Component (Files access control), and so on. Of course, ASPs can invoke standard ActiveX controls written by other users in addition to the built-in ActiveX controls.

You define the control before you use it, such as: <% set object variable name =server.createobject ("ADODB. Connection ")%&gt, or defined directly with HTML <OBJECT> and </OBJECT> tags, the effect is the same.

Example: <object runat=server

Id= object Variable Name

Progid= "ADODB. Connection ">

</OBJECT>

Once defined, we can begin to invoke its methods to match the relevant work.



A Methods and properties for embedding various ActiveX controls

1. Database access (DB access control)

This is a very important part, because more than 50% of the work is almost all about the database, the use of this control can be said to be essential. In ASP, use ADO (Active Data Objects) to access database data, and if it is a remote data source, you can use RDO (sqlremote data Objects). ADO includes the following seven object classes.

Command: Define some special commands syntax so that you can execute the appropriate program.

Connection: Provides links to OLE DB information sources.

Error: Used to describe errors that occurred while accessing the database.

Field: Takes a row as a reading unit of information.

Parameter: Parameters that need to be passed in when command is used.

Property: Records The dynamic characteristics of an ADO object.

Recordset: Used to save database information that is read back.

The following is one of the most common examples of steps to read database information and then publish the information. First create a system DSN named Test in the ODBC driver, link to any of your databases, and then use WordPad to make a suffix named. asp, which reads as follows.

<HTML><BODY>

<%

Set Dc=createobject ("ADODB. CONNECTION ")

; Define a Connection object for a DC

DC. OPEN "Test"

OPEN is a method of connection, if you are linked to access or FoxPro database, you can use the above method, if it is similar to SQL, Oracle and other user names and passwords to allow access to the database, you can pass the Dc.open "test" , "UID", "password" to open the database source.

Sql= "SELECT * from JOB"

Set RESULT=DC. EXECUTE (SQL)

; Execute is another method of connection to execute the SQL statement. This defines result as the Recordset object, which is used to receive the return results after the execution of the SQL statement. If you do not need to save the returned results, you can call the DC directly. EXECUTE SQL ".

Do as not result. Eof

RESPONSE. WRITE result ("NAME")

, assuming that name is a property of the database.

Result. MOVENEXT

, in addition to MoveNext, there are MoveFirst, MoveLast and other methods, similar to VB.

LOOP

Result. Close

%>

</BODY></HTML>

From the example above, it is clear that the most commonly used class for linked OLE DB information sources is the connection class, which includes open, EXECUTE, close, BEGINTRANS, CommitTrans, and RollbackTrans. If you are familiar with the rollback operation in SQL script, then the BeginTrans must not be unfamiliar, the last three methods are used to rollback some of the operations, the syntax is as follows (to add, if you can do in the database rollback operations, it is best to do in the database, Because it will be more efficient and will have less impact on the system.

BEGINTRANS

Syntax: [Level=]connection object. BeginTrans

Where level is a long type of variable that stores the level value returned by the BeginTrans method.

COMMITTRANS

Syntax: Connection object. CommitTrans

Stores all of the current actions and results.

RollbackTrans

Syntax: Connection object. RollbackTrans

Cancels all work that started from BeginTrans and initializes it again.

This is a detailed description of the most commonly used connection classes, and you can access the http://www.microsoft.com/ado/site if you want to learn more about database access's other class libraries.



2. Ad Rotator (Dynamic ad generation control)

The effect of advertising on the network is more and more people understand, "net Union" (Webunion) is a good example. A good advertising program is not easy to write, because you need to consider including how often the picture appears, the name of the picture, the address of the link, the size of the display, and the speed, efficiency, and maintenance issues. Of course, if you are a large site like webunion, this is necessary, but if you are just a small site, just want to simply dynamically display some pictures (including links) and facilitate maintenance, then ad Rotator dynamic ad generation control is definitely your first choice.

In order for you to have an intuitive understanding, we will first introduce the steps to create a dynamic ad, and then describe its methods. Generate dynamic advertising, involving three files:



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.