Basic Learning of ASP: Access+asp exercise A

Source: Internet
Author: User
Tags html page odbc sql reset
Access Practice One:
Establish a simple database add, display, query function implementation NOTE: [Adopt access2000+asp, Database: Customer.mdb (field: Company Name (character), telephone (data type), fax (data type), category (character), contact (character type), Notes (character type))]
< complete the test in WinXP pro+iis5.1 environment >
The page code is as follows:

---add.html----
<title> Add database Records </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body bgcolor= "#FFFFFF" >
<p align= "center" ><font size= "5" > Add database Records </font></p>
<form method= "POST" action= "adddatabase.asp" >
<div align= "center" >
<table width= "46%" border= "0" >
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Company name:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "CompanyName" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Telephone:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Tel" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Fax: </div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Fax" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "right" > Category:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Classes" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Contact person:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Cname" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Notes:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Backups" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "right" > </div>
</td>
&LT;TD width= "72%" >
<input type= "Submit" name= "submit" value= "Submit" >
<input type= "reset" name= "reset" value= "reset" >
</td>
</tr>
</table>
</div>
</form>
</body>

---adddatabase.asp---
<title> Add database Records </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body bgcolor= "#FFFFFF" >
<p align= "center" ><font size= "5" > Add database Records </font></p>
<form method= "POST" action= "adddatabase.asp" >
<div align= "center" >
<table width= "46%" border= "0" >
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Company name:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "CompanyName" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Telephone:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Tel" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Fax: </div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Fax" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "right" > Category:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Classes" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Contact person:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Cname" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "Right" > Notes:</div>
</td>
&LT;TD width= "72%" >
<input type= "text" name= "Backups" >
</td>
</tr>
<tr>
&LT;TD width= "28%" >
<div align= "right" > </div>
</td>
&LT;TD width= "72%" >
<input type= "Submit" name= "submit" value= "Submit" >
<input type= "reset" name= "reset" value= "reset" >
</td>
</tr>
</table>
</div>
</form>
</body>
---addnewdatabase.asp---
<%
Rs. AddNew
RS ("company name") = CompanyName
RS ("telephone") = Tel
RS ("fax") =fax
RS ("category") = Classes
RS ("Contacts") =cname
RS ("Memo") =backups
Rs. Update
%>

---viewdatabase.asp---
<%
Set Dbconnection=server.createobject ("ADODB. CONNECTION ")
DBPath = Server.MapPath ("Customer.mdb")
DbConnection. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & DBPath "to establish a connection to the database with the.
Sql= "SELECT * FROM Customers ORDER by company name DESC"
SET customerlist=dbconnection. EXECUTE (SQL)
%>
<body>
<font size= "5" ><center> database records </center></FONT>
<CENTER>
<table border=1>
<tr>

<td> Company Name </td>
<td> Tel </td>
<td> Fax </td>
<td> category </td>
<td> Contact Person </td>
<td> Notes </td>
</tr>
<% do, not customerlist.eof

' Detect if the record is the last one. EOF represents end of File.
%>
<TR>
<td><% =customerlist ("Company name")%></td>
<td><% =customerlist ("Telephone")%></td>
<td><% =customerlist ("fax")%></td>
<td><% =customerlist ("category")%></td>
<td><% =customerlist ("Contacts")%></td>
<td><% =customerlist ("Remarks")%></td>
</TR>

<%
Customerlist.movenext
Loop
' If you haven't got to the last one, the pointer moves to the next one. With Do While ... Loop loops to get all of the records individually.
%>
</TABLE>
</CENTER>
<center>
<input type= "button" value= "Add Data" >
</center>
</BODY>
</HTML>

===================

The problem resolution occurs:

1.
<%
Set Dbconnection=server.createobject ("ADODB. CONNECTION ")
DBPath = Server.MapPath ("Customer.mdb")
DbConnection. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & DBPath "to establish a connection to the database with the.
Sql= "SELECT * FROM Customers ORDER by company name DESC"
SET customerlist=dbconnection. EXECUTE (SQL)
%>

1). Sql= "SELECT * FROM Customers ORDER by company name DESC" If the field name "Company Name" is incorrectly written, such as "Company", the following error message appears:

Error type:
Microsoft OLE DB Provider for ODBC Drivers (0X80040E10)
[Microsoft] [ODBC Microsoft Access Driver] has insufficient parameters, expect to be 1.
/viewdatabase.asp, line 6th.

Correct field names with the correct field names for the database fields. This will correctly display the correct information, such as when you use the Network Pig Browser, you can not display the default item add.html page. The reason is not clear
Mircrosoft Internet Explorer and Myie as well as Firefox browser can display the expected results normally.

2.
<%
Set rs=server.createobject ("ADODB. Recordset ")
Rs. Open "Customers", DbConnection, adopendynamic,3
%>

1). adopendynamic,3
When the above statement is missing, you will get the following results:

Error type:
ADODB. Recordset (0X800A0CB3)
The current Recordset does not support updates. This may be a limitation of the provider or the selected lock type.
/adddatabase.asp, Line 26th.

Thus it appears that the "adopendynamic,3" is equally indispensable in the Recordset setting value. Of course this "3" meaning should be: the current data record is read-only, can move freely. Change to "2", and replace "1" or not, will not display the expected results normally
is displayed as the error type above:

ADODB. Recordset (0X800A0CB3)
The current Recordset does not support updates

==========================================================
Excerpt: sql= "SELECT * from user where account = '" &zh& "' or name = '" &name& "'"
Set rs= Server.CreateObject ("ADODB.") Recordset ")
Rs.Open sql,conn,1,1

1,1 is a general inquiry! 3,3 can be divided into pages! 2,2 I didn't use it!
===============================================



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.