Learning Purpose: Mastering accessDatabasethe connection and read 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 ADODBDatabaseConnectionComponent, the second sentence is connected.Database, you just change the back of theDatabaseName on it. 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 after the first two sentences: Set up the queryDatabasecommand, the Select is followed by the field, if you want to query the words to use the *,from followed by the name of the table, we are established in front of a gustbook table ah? Second sentence: Define a recordsetComponent, all the search records are in here, the third sentence is to open the Recordset, Exec is the query command defined earlier, Conn is the previously definedDatabaseConnectionComponent, followed by the parameter "1,1", which is read, followed by 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 is the picture of the result above my machine. turn from: Dynamic Network production guide www.knowsky.com |