I. Designing the database ASP program itself does not store data, but as a message book, some necessary information needs to be stored, such: the name, contact information, message content, and time of the message recipient. This information is stored in the database. As the message book is a simple application, we choose lightweight access as the background database. Open Access 2003 and create a new name named data. mdb database, and create a table named main in it. This table is mainly used to store the visitor's message. The table structure is as follows: Then add two records to the database as our test data. 2. for overall web page planning, we need the following web page file 1 and index. ASP ---- the homepage displays the message page 2, Conn. ASP-a public webpage. Each webpage must contain it. It is used to connect to open a database. 3. Post. asp ----- post rumor page 4. Save. asp ---- Save the message page. 5. Del. ASP ---- Delete message page 6, admin. ASP ---- administrator homepage 7. login. ASP --- create a conn using Dreamweaver on the background management login page. ASP page, as follows: these lines of code function: the first line of code: used to create a connection object for data storage to provide connection line 2 code: Set database connection parameters. Including the database driver and database file name. Line 3: Use conn to connect to the database. The above is a common method for connecting to the database, which can be used elsewhere. Create an index. asp page in Dreamweaver. The specific process is as follows: first create a table with one row and one column to display the title of the message book. Of course, you can also put some pictures or animations. Insert a table with one row and one column, which is the subject of the entire message base. In this table, insert another table to display the specific content of the message. After the layout is complete, insert the following ASP code in the Code view: insert the code at the top of the webpage Code <! -- # Include file = "Conn. ASP "-->, so the Conn is inserted. ASP database connection code page. This code is included in the current webpage for normal compilation and does not need to repeatedly write the database connection code. It has great advantages to make the page structured, it is easy to modify and maintain. If the database connection is incorrect or the database file changes, you only need to change the conn. ASP. You do not need to modify the code on each page. Be good at using this method to simplify and clarify your program. This is a common programming method. Then in index. the VBScript code is inserted at the following position on the ASP page, as shown in the red box. The code indicates line 3: Since the webpage and database are connected and opened with connection, then the most important task is to read data. Create an RS object variable as A recordset object. In this way, you can use the RS object variable to access the database. Line 1 code: place the query results from the data table main to SQL variables. It means that all the data in the main table is retrieved and sorted by ID from large to small. Desc indicates sorting from large to small. If this parameter is not added, the latest message is displayed at the end, which is inconvenient. Line 1 code: Use the RS object variable open method to open the data table main, and retrieve the results obtained by the SQL query method.
The above is a general method for reading records. You can use it elsewhere! Lines 32 and 33: point the RS record pointer to the first record, and then start to judge whether the end of the record is null when moving the record. If not, move the pointer, read all the data. Exit the loop until the end is null. Add the loop body end code at the following position: note that the position of the Code must be correct. Otherwise, the output HTML code is incorrect, here we are the rows in the Big Table with one column in the External Loop. In the future, each row is used to display a message, and each row is a table, it is used to layout the displayed message information. Then, the most important thing we do is to read the records of fields in the data table and place them in different positions in the table. The code after writing is as follows: OK, so far, we can open our index in the browser. ASP Page Preview. If no error occurs, two message records are displayed.