Implement data query and input with ASP

Source: Internet
Author: User
Tags date execution implement informix odbc sql query reset
Data with the rapid development of Internet technology, computer in various industries more and more play a pivotal role. The use of advanced information technology and database technology to build intranet within the company, the development of web-based database management system, can greatly improve work efficiency and cost savings. ASP (Active server Page) is a Microsoft launched server-side command execution environment, not browser-independent, the script is run entirely on the server, will generate dynamic information, the formation of ordinary HTML files, sent to the client. ADO (ActiveX Data Objects) is the ASP built-in ActiveX server component, can realize "immediate updating, real-time display" the newest Web database technology in the client side, can conveniently through the browser page realizes to the data input, the inquiry, the update and so on the operation.











one, using ASP and ADO to implement the work flow of database operation





ASP Embedded Five objects resquest, Response, Server, seesion, application, to achieve information acquisition, transmission and preservation. The main objects of ADO are connection, Command, Recordset and so on. Using ADO's Connection object and ODBC's setting, we can establish the connection with a variety of databases (Informix, Oracle, access, etc.), so as to realize data input, query and update operation. First, using the CreateObject method of ASP's server object to create an object instance of ADO, the Connection object of ADO is used to establish the connection between the corresponding database and the application program. Then, The Command object assigns the SQL (Standard Query Language) Standard Description Statement of the data request to the properties of the Command object, and then executes the input, query, and so on of the database; The database server stores the data results of the response to the Recordset object, which can be processed, parsed, and displayed on the client browser in a server-side scripting locale.











Two, realize the data input, query instance





The company's branches are numerous, widely distributed, the parent organizations often have to the basic institutions of the business data collection, statistics. Previously mainly through the telephone to report data, and then manually summary, statistics, compiled into a report. With the company's internal networking, you can combine the network technology and database technology, data aggregation, statistics to achieve automation. The following will be done in conjunction with the company's reality by connecting to the Informix database:











1. Create DATABASE





creates a database of data rollup and statistics on UNIX operating systems and names the database as Cxdb, creating the following table on this database:





Create table Test





(





BR Char (6), #单位代码





dt date, #日期





SCO Money, #业绩





)





2. Connection Database





on the WINDOWS98 operating system, install the database connection driver informix-cli and run INFORMIX-CLI SetNet32 to configure and then run Ilogin Demo test configuration is correct. After confirming that the configuration is successful, you can implement various operations on the Web database. You can connect to a UNIX-side database by adding the following statement to your Web page:











Set con=server.createobject ("ADODB. Connection ")





Con.open "Driver={informix-cli 2.5 (32BIT)};D atabase=cxdb; server=11.32.65.45; uid=; Pwd= "











Where driver is the connection driver for the database, its string is consistent with the name in the ODBC driver; The database is the name of the databases, the server is the IP address or name of the database server host, and if it is a name, the hosts file must be edited; uid is the user name ; pwd is the password.





3. Implement data input, query





in order to realize the input and query function of the data, a file with form form must be created to accept the user's data input and query conditions, and the Post method is used to submit the form data to the server for processing.





Editor accepts the user input file input.asp, the user enters "the unit", "The Date", "The performance", when the user clicks the Submit button, through the Post method sends the data which just entered the Web server, and executes todb.asp file to add a record in the database Cxdb. Where the source code for input.asp and todb.asp is as follows:





input.asp:





<HTML>











<HEAD>





<TITLE> input Data </TITLE>





</HEAD>











<BODY>





<form method= "POST" action= "todb.asp" >





<P> Unit: <input type= "text" name= "T1" size= ">
"




<P> Date: <input type= "text" name= "T2" size= ">
"




<P> performance: <input type= "text" name= "T3" size= ">
"




<p><input type= "Submit" value= "submitted" name= "B1" >





<input type= "reset" value= "rewrite" name= "B2" >





</FORM>





</BODY>











</HTML>





todb.asp:





<% br=request.form ("T1")





dt=request.form ("T2")





sc=request.form ("T3") extracts the data from the Input.asp form into the variable BR,DT,SC











Set con=server.createobject ("ADODB. Connection ")





Con.open "Driver={informix-cli 2.5 (32BIT)};D atabase=cxdb; server=11.32.65.45; uid=; Pwd= "





' above two statements for establishing ADO objects and connecting to the database





sql= "INSERT into Test (BR,DT,SC) VALUES (' &br&" ', ' "&dt&" ', ' "&sc&") "





Set Rs=con.execute (SQL) Execute SQL statement to add data to the database





Rs.close





Con.close





%>





data query and input the same implementation, but the execution of the SQL statement is different, query execution is to meet the user input criteria of the SELECT statement. The source code is as follows:





indt.asp





<HTML>











<HEAD>





<TITLE> input Conditions </TITLE>





</HEAD>











<BODY>





<form method= "POST" action= "seldt.asp" >





<P> Date: <input type= "text" name= "T1" size= ">
"




<P>





<input type= "Submit" value= "submitted" name= "B1" >





<input type= "reset" value= "rewrite" name= "B2" >





</FORM>





</BODY>











</HTML>











seldt.asp





<HTML>











<HEAD>





<TITLE> Execute the query and display the results &l







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.