Connect via ASP with Access database (with source code) (3)

Source: Internet
Author: User
Tags connect access database

III) Show/View database records:

<%
Set Dbconnection=server.createobject ("ADODB. CONNECTION ")
DBPath = Server.MapPath ("Customer.mdb")
DbConnection. Open "Driver={microsoft Access driver (*.mdb)};d bq=" & DBPath

Establish a connection with the database, with the same.

Sql= "SELECT * from Customer Order by Time DESC"
SET customerlist=dbconnection. EXECUTE (SQL)
%>

Creates an SQL query statement that queries all records from the Customers table, and the order by time DESC indicates "Sorted by time," so that the last added information is displayed on top. The following sentence executes the SQL query and returns the result to the Recordset object customerlist.

<body>
<font size= "5" ><center> database records </center></FONT>
<CENTER>
<table border=1>
<tr>

<td> number </td>
<td> Company Name </td>
<td> Contact person's name </td>
<td> City </td>
<td> Phone number </td>
</tr>
<% do, not customerlist.eof%>

Detect if the record is the last one. EOF represents end of File.

<TR>
<td><% =customerlist ("customer number")%></td>
<td><% =customerlist ("Company name")%></td>
<td><% =customerlist ("Contact person name")%></td>
<td><% =customerlist ("City")%></td>
<td><% =customerlist ("phone number")%></td>
</TR>

<% =customerlist ("customer number")%> can be said to be a shorthand for the Response.Write method. Writes the data in the customer Number field to the TD tab.

<% Customerlist.movenext
Loop
%>

If you have not yet arrived at 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>

Flaw: Only the most basic functions are realized. Do not say other functions, only on the data to add and view the function, more perfect should also add "paging function." Otherwise, it is basically impossible to show all the data to a certain extent.
This period is complete.




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.