Implementation of SQL SERVER database operations in ASP language

Source: Internet
Author: User
Tags generator odbc query microsoft frontpage
At present, the management information system has shifted from the traditional client/server (c/s) mode to the browser/server (b/s) mode, especially after Microsoft introduced its new product ASP language, this change is more rapid. Management Information System is the core of the database including add, modify and query operations, ASP provided by the ADO Database interface control, so that programmers no longer need to write a complex CGI program, and as long as a few simple sentences can achieve the above operation. There are many examples of programs that use ASP to develop network databases, but most of them use access as the underlying database. SQL Server database systems are much more complex than access, so you need to do more work in program development. The author unifies own development Management information system's experience, in this try to cite one example, with the interested friend exchanges together.

----1, System environment

----PII 350,ram 64m,winnt Server 4.0,
Service Pack4, IIS 4.0, SQL Server7.0.

----2, System function

----through the use of IE browser, on the internet to achieve the "Office document" data table records add and query.

----3, Function realization

----(1) Data table settings

----① to start the Enterprise Manager for SQL Server7.0,
Add a new subdirectory "test" in the databases directory;

----② adds a new table under "Test", named "Office File", field settings: FileName, char,100, allow null, file content, char,4000, allow null.

----③ adds a user to SQL Server named HXL, password 123, login mode for SQL login, and set its default login database to "test";

----④ adds a new user under the "test" database, named Hxl, whose role is set to "Dbowner".

----(2) ODBC link

----① in Control Panel, open the ODBC data source, select the System DSN entry, and click Add;

----② Select the SQL Server data source, named "Test";

----③ Select login mode for SQL Server authentication, login flag is "HXL", Password is "123";

----④ The default database high to "test", then test the database link, and then connect.

----(3) Procedural documents

----in order to realize the system function, here edited 3 program files, respectively "index.html", "add.asp" and "query.asp", the specific contents are as follows:

----①index.html: System home page, including two options, one is to append records, the second is the query, the user can click one of the two, you can enter the corresponding operation process. The following are the source programs:

< HTML >
< head >
< meta http-equiv= "Content-language"
Content= "ZH-CN" >
< meta http-equiv= "Content-type"
Content= "text/html; charset=gb2312 ">
< meta name= "generator" content= "Microsoft
FrontPage 4.0 ">
< meta name= "ProgId" content= "FrontPage
. Editor.document ">
< title > Sample Program </title >
< BODY >
< p align= "center" >
< font size= "5" color= "#008000" >
Welcome to use ASP language for SQL
Server database Operations Sample </font ></p >
< p align= "center" > </p >
< p align= "center" >< a href= "add.asp" >
Append Records </a ></p >
< p align= "center" >< a href= "query.asp" >
Queries </a ></p >
</body >

----②add.asp: The realization of the "Office document" data table records added. The page contains a single-line text box
(Txtbiaoti) and a scrolling text box (Txtneirong), used to enter the file title and file contents, respectively. In addition, there should be two buttons on the page, OK (Cmdok) and rewrite (cmdcancel), click OK to complete the record append, and click "Rewrite" to re-enter the content. The following are the source programs:
< HTML >
< head >
< meta http-equiv= "Content-type"
Content= "text/html; charset=gb2312 ">
< meta name= "generator" content=
"Microsoft FrontPage 4.0" >
< meta name= "ProgId" content=
"FrontPage.Editor.Document" >
< title > Add a new record </title >
< BODY >
<% if Request.Form ("Cmdok") = "OK" then% >
<%
Set Dbconnection=server.createobject
("Adodb.connection") dbconnection.open "test", "HXL", "123"
sqlquery= "Insert" Office files
(filename, file content)
VALUES (' Request.Form ("Txtbiaoti") ', '
Request.Form ("Txtneirong")
Set Recadd=dbconnection.execute (sqlquery)% >
<% Else% >
< p align= "center" > Append record </p >
< form method= "POST" action= "" >
< p > FileName:< input type= "text"
Name= "Txtbiaoti" size= "></p >
< p > File content:<//>
< p >
< textarea rows= "3"
"Txtneirong" cols= "name=" ></textarea >
</p >
< p align= "center" >< input type= "Submit"
Value= "OK" name= "Cmdok" >
< input type= "reset" value= "rewrite"
Name= "Cmdcancel" >
</p ></form >
<% end if% >
</body >

----③query.asp: To achieve the "Office document" data table records of the query. The program only implements a query for "file name" in the Office file, and the results are listed in a form (table). The following are the source programs:
< HTML >
< head >
< meta http-equiv= "Content-type"
Content= "text/html;charset=gb2312" >
< meta name= "generator" content= "Microsoft
FrontPage 4.0 ">
< meta name= "ProgId" content=
"FrontPage.Editor.Document" >
< title > Retrieval file </title >
< body bgcolor= "#ffffdd" >
<%
Set Dbconnection=server.createobject
("Adodb.connection")
Dbconnection.open "Test", "HXL", "123"
sqlquery= "SELECT file name from Office file"
Set Resultlist=dbconnection.execute (sqlquery)
% >
< Center >
< font color= "Red" ><%=request ("Selectsource")% >
</font >< font color= "#008000" size= "5" >< B >
The following documents are available for reading </b ></font >
< hr size= "5" >
< table border= "1" >
< tr >
< TD width= "align=" "Center" > < b >
File name </b > </td >
</tr >
<% do resultlist.eof% >
< tr >
< TD Valign=center Width= "" ><%=resultlist
("filename")% ></a ></td >
</tr >
<%
Resultlist.movenext
Loop
Resultlist.close
% >
</center >
</table >
</body >

----4, Summary
----Use IE to open index.html or publish files to the site, the corresponding operation, you can achieve the SQL Server database system, "Office files" data table records of the Append and query, the system has achieved the goal.


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.