ASP advanced article online management update-database connection <P style = line-height: 150%> author: Beach kiddies <P style = line-height: 150%> in the previous section, we introduced the database structure of the article management system. After creating a database, we need to use ASP to establish database-related programs, including connecting to the database, displaying the database content, updating the database and other related programs, so this article will show you how to connect to the database in the management system and open the database. In ASP programs, programs that establish database connections are generally put into a single file separately, and will be directly used later <! -- Include file = "xxx. asp "-->, it is more convenient to change the database name in the future. If you write the database connection Statement on every page, and if you modify the database name in the future, you do not need to modify every file. Now you have used a separate file to directly INCLUDE it, only one file can be modified to achieve the same effect, which is also a small skill in ASP programming :) <P style = line-height: 150%> The following describes how to establish a database connection: <P style = line-height: 150%> Create an ASP file conn. asp. You can call the database later. <! -- Include file = "conn. asp" -->. The content and description of conn. asp are as follows: <P style = line-height: 150%> <% Dim conn Dim connstr <P style = line-height: 150%> "execution subroutine Call conn_init () <P style = line-height: 150%> "subprograms connected to the database Sub conn_init () <P style = line-height: 150%> "to respond to program interruptions caused by incorrect running time, it can move the control to the statement next to the wrong statement generated, you can continue to process the application without using this statement. Once an error occurs, the program stops and an error message is displayed to the user! On error resume next <P style = line-height: 150%> "use server. MapPath to specify the database path. The path here is the relative path. Connstr = "DBQ =" + server. mappath ("bookid. mdb") + "; DefaultDir =; DRIVER = {Microsoft Access Driver (*. mdb )};" <P style = line-height: 150%> "connect to the database using the Connection object Set conn = server. createobject ("ADODB. CONNECTION ") <P style = line-height: 150%> "open the connected database Conn. open connstr End sub %> In this way, a complete database connection and file opening are completed, and the database and its connection are completed. Next, we should introduce how to add data to the database, of course, it cannot be added directly to the database, so it will lose the meaning of this program :) the next section will introduce you to online addition and storage of articles. |