ASP advanced article online Management update (2)

Source: Internet
Author: User

The previous section introduces the database structure of the article management system, after the establishment of the database, it is necessary to use ASP to establish a database-related procedures, including the connection to the database, display database content, update the database and other related programs, so this article will tell you how in the management system to connect with the database, and open the database. In the ASP program, generally will establish the database connection program to separate into a file, then directly with the <!--include file= "xxx.asp"--> to call on it, This eliminates the need to set up a database connection in the future page to enter the relevant statements each time to establish a connection, but also to change the name of the database more convenient. You think about it, if you write on each page to connect the database statement, then if you modify the database name is not to be changed every file, now use a separate file directly include, as long as the modification of a file can achieve the same effect, which is also a small ASP programming skills:

Here's how to set up a connection to a database:

Create a new ASP file conn.asp, the subsequent call to the database can be used <!--include file= "conn.asp", the following is conn.asp content and explanation:

<%
dim conn
dim connstr
"执行子程序
call conn_init()
"连接数据库的子程序
sub conn_init()
"对由于运行时间错误造成的程序中断做出反应,它可以通过把控制移到生成错误的语句之后紧接的哪个语句,而继续处理应用,你也可以不用这个语句,这时一旦发生了错误,程序会停止并且有一个错误提示信息给用户!
on error resume next
"利用server.MapPath来指定数据库的路径,这里的路径是相对路径
connstr="DBQ="+server.mappath("bookid.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
"利用Connection对象连接数据库
set conn=server.createobject("ADODB.CONNECTION")
"利用open打开连接的数据库
conn.open connstr
end sub
%>

In this way, a complete database connection and open file is done, the database and its connection are done, next should introduce how to add data to the database, of course, can not be directly added to the database, which lost the meaning of this program: the next section will introduce the article online add and save.

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.