Tutorial/asp 10 days to learn the fourth day of ASP

Source: Internet
Author: User

Learning Goals: Mastering Access database connections and reading records

What to learn today is a bit boring, but very important. Here we do not need to know the specific operation of the command, outside a lot of books are not suitable for the introduction is because of the introduction of too much theoretical knowledge, so that beginners confused.

let's go straight to the bottom and see two words:

<%
Set Conn=server.createobject ("Adodb.connection")
Conn.Open "Driver={microsoft Access Driver (*.mdb)};d bq=" &server.mappath ("Example3.mdb")
%>

The first sentence defines a ADODB database connection component, the second sentence is connected to the database, you just modify the database name on the back. Is it simple?

look at the next three sentences:

<%
Exec= "SELECT * FROM Guestbook"
Set Rs=server.createobject ("Adodb.recordset")
Rs.Open exec,conn,1,1
%>

These three sentences are added to the first two sentences: Set the query Database command, the Select is followed by the field, if you want to query the words with the *,from followed by the name of the table, we are not established in front of a gustbook table ah? Second sentence: Define a recordset component, all the search records are placed here, the third sentence is to open this Recordset, exec is the previous definition of the query command, Conn is the previous definition of the database connection component, the next parameter "1,1", which is read, after the modified record to set the parameter to 1, 3, OK. Next we read the record.

<table width= "100%" border= "0" cellspacing= "0" cellpadding= "0" >
<%do While not rs.eof%><tr>
<td><%=rs ("name")%></td>
<td><%=rs ("tel")%></td>
<td><%=rs ("message")%></td>
<td><%=rs ("Time")%></td>
</tr><%
Rs.movenext
Loop
%>
</table>

In a table, we use 4 columns to display the last set of four fields, with Do loop, not rs.eof means that the condition is not read to the end of the recordset, rs.movenext means to show a go to the following record,<%=%> is equal to <%response.write%> used to insert ASP code inside the HTML code, mainly for displaying variables.
  
Well, today is over, we can practice, you can download my example to see, debugging. Here's a picture of the results on my machine.



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.