Using ASP to maintain database online

Source: Internet
Author: User
Data | database | Online with the development of Internet, database application has been developing in the direction of simple operation and practical function in the network environment. This paper introduces how to use ASP technology to realize
The method of online maintenance of database and the realization process of various function keys are given.
Implementation features
Database administrators can maintain databases directly on the Web. In the data query and database maintenance interface (see Figure 1), select the data rows you want to manipulate by using the check boxes.
and select what you want to do with the radio button in the Function key area, and then press the submit button to do what you want and get the return information (see Figure 2)

Figure 1 Data query and database maintenance interface

Figure 2 Returning the information prompt interface

The implementation environment is as follows:
Client: Windows 98 operating system +ie 5.0 Browser
Server-side: SQL Server 7.0 Database
Web site Application Development environment: Active Server Pages (ASP)
Web page Production development environment: Microsoft FrontPage 2000
Programmatic implementation
First, use FrontPage 2000 to compile the data query and database maintenance interface, and establish an association with the background SQL Server database standard, from the data
Check the data in the library table and generate the data collection Rs. To speed up program Access, you can save it in the Session object Rs1. Some 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);D atabase=info; Uid=user; Pwd=password; ", 3,2
Set session ("Rs1") =rs
%>
Insert a form, add a function key such as INSERT, delete, modify, and set the group name of the radio button at the function key to edit, and the button value points
Do not correspond to "insert", "delete", "Update".
Then, write the ASP program tzwh1.asp file. Reads data from session, separates it with a split function according to the data item, and converts it into an array
Row processing and using the TRIM function to remove the space before and after the data. Part of the code for the program is as follows:
<% set Rs=session ("Rs1")
Edit=trim (Request ("edit")
Id= "," &trim (Request ("id")) & ","
Eno=split (("NO"), ",")
Etitle=split (Trim (Request ("title")), ","
Epdate=split (Trim (Request ("pdate")), ","
Ewriter=split (Trim (Request ("writer")), ","
Econtent=split (Trim (Request ("content")), ","
%>
Finally, implement the function key. The choice of function keys is implemented with case statements. In each implementation process, the InStr comparison function is used to read out the ENO and data items
Identification ID, which identifies whether the selected check box is valid. The lower bound of a For loop body uses the UBound function to avoid the error of extracting the data from the Web page. Department
The 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>
&LT;TD align= "center" ><% =rs ("Pdate")
%>.</td>
<td><font color= "#008080" ><% =rs ("title")%>.</font></td>
<td><font color= "#008080" > Insert new Record Success! </font></td>
</tr>
<% End If
Next%>
<% case "Delete"
For I=0 to 9
If INSTR (ID, "," &trim (RS ("id")) & ",") >0 then%>
<tr>
&LT;TD align= "center" ><% =rs ("Pdate")
%>.</td>
<td><% =rs ("title")%>.</td>
<td><font color= "#ff0000" > record deleted successfully! </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>
&LT;TD align= "center" ><% =rs ("Pdate")
%>.</td>
<td><% =rs ("title")%>.</td>
<td><font color= "#0000ff" > Record modification Success! </font></td>
</tr>
<% End If
Rs.movenext
If Rs.eof then Exit for End If
Next
End Select
%>



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.