To implement a Web query for an Access database

Source: Internet
Author: User
Tags table name access database

ISAPI and DAO Introduction

ISAPI (Internetserverapplicationprgramminginterface) is a Microsoft-provided API that is tightly integrated with its IIS. It can be used to compile Internet/intranet database, network management and BackOffice applications.

The Data Access object (DAO that is Dataaccessob jects), is originally the programmable interface designed by Microsoft for VisualBasic and Accessbasic. Later, with the oleautomation (automatic control) technology, it can be used in C + + programming.

Programmers can use the three types of DAO to compile C + + code:

*daooleautomation interface;

*dbdao class;

*mfcdao class.

The Dbdao class and the VisualBasic DAO class are very similar, easy to use, the author is to use it for database programming.

Table 1 Explanation of the attribute variables in the corresponding data field class in the macro variable name form

Sztxtdatabasenamedatabasenamem-szdatabasename database name

Sztxttablename tablenamem-sztablename table name or query name

Sztxtfieldnamefieldnamem-szfieldname search Field Name

Sztxtfieldvaluefieldvaluem-szfieldvalue field value

Programming background

Now a lot of small and medium-sized enterprises or departments of the database are based on access, and its general use of Client/server mode to build mis. In today's popular internet/intranet and will become the mainstream in the future situation, it is necessary to move the original database to Internet/intranet.

Many people are using ASP, IDC, VB sc ript, ja vasc ript, Perl, and even SHELLSC ript to make Web applications, although they are easier to compile than ISAPI, but they are less secure and more flexible than C, C + +, so As a more professional programmer, it is wiser to choose to use high-level languages such as C + + to make Web applications.

Microsoft's system and development software is in vogue, based on the above factors, the author uses visualc++ (more than 4.2) to provide the ISAPI and DAO development tools, design the Access database General internet/intranet query program, Can run on Web servers such as IIS2.0, Peerwebserver, and Personalwebserver.

Introduction to the application methods and functions of the program

After the program compiles the connection, it generates Search.dll, which is placed in the Web server's executable directory (such as/cgi-bin).

The Web home page producer can insert the following HTML fragment into the page:

〈formaction=″/cgi-bin/search.dll″method=″get″〉

〈in puttype=″hidden″name=″databasename″value=″northwind.mdb″〉

〈in Puttype=″hidden″name=″tablename″value=″ Products ″〉

〈in Puttype=″hidden″name=″fieldname″value=″ Product Name ″〉

〈p〉〈in puttype=″text″name=″fieldvalue″size=″30″〉〈/p〉

〈p〉〈in Puttype=″submit″value=″ Press this query ″〉〈/p〉

〈/form〉

The above three "hidden" type of input data by the home page production personnel input, in the browser does not display, in order to interface beautiful, fieldvalue by the customer by the browser fill in the data. Each of the four data fields is explained as follows:

*databasename:access database name, default in%system%system32 directory, such as enter full path name, then in C language format, such as: C:datamydata.mdb.

*tablename: Table name or query name, you can customize a query that conforms to the output.

*fieldname: The name of the field to use as a query condition, which is a text type.

*fieldvalue: Field value, entered by the customer.

After the customer enters data in the browser and presses the query button, the server outputs the following query results:

Select*fromtablenamewherefieldnamelike″*fieldvalue*″

Because * for access query the wildcard character of the statement, so this program can implement the fuzzy query based on field fieldname.

program flow and Main function description

Figure 1 Process for a customer request in this program

(i) header file MyTable.h

1. Defines 4 macro variables corresponding to the four input data fields in the form, which are used to parse parameters to obtain values, as shown in table 1. (Next turn B7 version)

2. Derived class cmytableextension that defines the CHttpServer class:

Classcmytableextension:publicchttpserver

{

Public

Cstringm-streaderror;

Lpstrm-szdatabasename;

Lpstrm-sztablename;

Lpstrm-szfieldname;

Lpstrm-szfieldvalue;

Voidcdbsetuppage (Cstring&stpage);

Charatoihex (Charch);

Parsein put function to parse customer input data

Boolparsetin put (Lpstrszin put,lpstrszitem,lpstr*pszdata);

Strvariant function converts variant variable values to generic data type values

Cstringstrvariant (Constcolevariant&var);

Cmytableextension ();

~cmytableextension ();

{{afx-virtual (cmytableextension)

Public

Virtualboolgetextensionversion (Hse-version-info*pver);

Virtualdwordhttpextensionproc (EXTENSION-CONTROL-BLOCK*PECB);

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.