Tutorials to .com

Tutorials to .com » Asp » Database » Online maintenance of the database using ASP

Online maintenance of the database using ASP

Print View , by: iSee ,Total views: 9 ,Word Count: 1096 ,Date: Mon, 25 May 2009 Time: 5:40 PM

With the development of the Internet in a networked environment, the database application gradually to the simple, functional and practical direction. This article describes how to use asp technology to achieve
Online database maintenance method of the realization of the various function keys process.
To achieve functional
database administrator to maintain on-line database directly. In the data query and database maintenance interface (see Figure 1), through the check box to select the data line operation,
And function through the keypad to select the radio button, then press the "submit" button, you can carry out the necessary operations, and the return of information (see Figure 2)

Figure 1 data query and database maintenance interface

Figure 2 return message interface

The realization of the environment are as follows:
Client: Windows 98 operating system, browser + IE 5.0
Server: SQL Server 7.0 database
Web application Development Environment: Active Server Pages (ASP)
Page Creator development environment: Microsoft frontpage 2000
Programming
First of all, the FrontPage 2000 with the preparation of data query and database maintenance interface, the background through the SQL Server database and associated standard, from the data
Library access to the data table to generate a data set rs. In order to speed up access speed, can be stored in the session object in rs1. Part of the code is as follows:
<%
sql = "select * from inform order by pdate DESC"
Set rs = Server.CreateObject ( "ADODB.Recordset")
rs.Open sql, "Driver = (SQL Server); Server =
(local); Database = info; UID = user; PWD = password; ", 3,2
set session ( "rs1") = rs
%>
Insert a Form, add "Insert", "delete", "amendment" and other function keys, Office function keys and the radio button group name is set to edit, the value of sub-button
Do not correspond to "insert", "delete", "update".
Then, the preparation of ASP files tzwh1.asp procedures. Read data from the session, according to data item to use split function to separate into an array into the
Line processing, and trim function to remove spaces before and after data. Procedural part of the code is as follows:
<% Set rs = session ( "rs1")
edit = trim (Request ( "edit"))
id = "," & trim (Request ( "id "))&","
eno = split (trim (Request ( "NO")), ",")
etitle = split (trim (Request ( "title")), ",")
epdate = split (trim (Request ( "pdate")), ",")
ewriter = split (trim (Request ( "writer")), ",")
econtent = split (trim (Request ( "content")), ",")
%>
Finally, the realization of function keys. The choice of function keys words the realization of use case. The realization of each process, the use of relatively inStr function will read out data item and eno
Id identification number, compared to identify the validity of the selected check box. for the lower bound of loop Ubound function used to avoid the web page extraction of data error. Department of
Sub-program code is as follows:
<% Select case edit
case "insert"
for i = 0 to Ubound (eno)
if inStr (id, "," & trim (eno (i ))&",")> 0 then
rs.AddNew
rs ( "title") = trim (etitle (i))
rs ( "pdate") = trim (epdate (i))
rs ( "writer") = trim (ewriter (i))
rs ( "content") = trim (econtent (i))
rs.Update
%>
<tr>
<td align="center"> <% = rs ( "pdate")
%>.</ Td>
<td> <font color="#008080"> <% = rs ( "title") %>.</ font> </ td>
<td> <font color="#008080"> insert a new record of success! </ font> </ td>
</ tr>
<% End if
Next%>
<% Case "delete"
for i = 0 to 9
if inStr (id, "," & trim (rs ( "id "))&",")> 0 then%>
<tr>
<td align="center"> <% = rs ( "pdate")
%>.</ Td>
<td> <% = rs ( "title") %>.</ td>
delete <td> <font color="#FF0000"> record success! </ font> </ td>
</ tr>
<%
rs.delete 1
End if
rs.movenext
if rs.eof then Exit for End if
Next
case "update"
for i = 0 to 9
if inStr (id ,","& trim (rs ( "id "))&",")> 0 then
rs ( "title") = trim (etitle (i))
rs ( "pdate") = trim (epdate (i))
rs ( "writer") = trim (ewriter (i))
rs ( "content") = trim (econtent (i))
rs.Update%>
<tr>
<td align="center"> <% = rs ( "pdate")
%>.</ Td>
<td> <% = rs ( "title") %>.</ td>
modify <td> <font color="#0000FF"> record success! </ font> </ td>
</ tr>
<% End if
rs.movenext
if rs.eof then Exit for End if
Next
end select
%>


ASP Database Related Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.