You already know simple SQL from reading Charles' ColdFusion article,right? Ifnot, just give this onepage a read. OK, say we throw the following SQL statement at our database:SELECT carID, carName FROM Cars ORDER BY carID. The server willreturn what's known as an ADO recordset to the ASP document. What is arecordset? It's a two-dimensional array. What's a two-dimensionalarray? It's essentially a table. Below I have a visual representation ofthe recordset that would be retrieved. Let's say I've loaded this recordsetinto a variable called Cars.
»»»»»» | beginning of file (bof) |
| 1 | Porsche 911 | |
| 2 | Mercedes B11 | |
| 3 | Jaguar XJ6 | |
| end of file (eof) | | |
The »»»»»» you see above indicates animaginarystarting point, which I'll refer to as a cursor. Thereare quite a few cursor types available for ADO recordsets, and Isuggest you look at a completelist when you get the chance. But keep in mind that, at this point,support for many of these cursors is sketchy at best. There are two basic things we're going to do with our cursor. The first isto ask questions about its location. Theposition of the cursor indicates we're at the start of thisrecordset, or the bof. So, what's the answer to the question,"Is cars.bof?" It's "true."Make sense?
The second thing we're going to do with our cursor is give itorders, like, "move to the next record," for example. With that in mind, youcan probably see how the following code snippetwould scroll through the cars recordset.
<% do while not cars.eof %><%= cars(1) %> <br><%cars.movenextloop%>
When the cursor reaches the eof position, the loop stops.
The only thing in this code that might be unclear is thecars(1) part. As I mentioned earlier, the recordset is a two-dimensional array. In an array, you refer to elements by their numericalposition, starting with 0 (it may seem weird, but Perl, JavaScript, and Call deal with arrays in this manner, so you should get accustomed to it).
In our SQL statement, SELECT carID, carName FROM Cars ORDER BYcarID, cars(1) will contain the second item (carName), the text fromthe carName field.
Now that you understand, let's take a pass at VBScript.
next page»