Datasheet
Dim dataReader As System.Data.OleDbDataReader = _
dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
If Not dataReader.HasRows Then
Response.Write("No rows found")
Else
While dataReader.Read()
Response.Write(datareader("ProductName") & "<br/>")
End While
End If
dataReader.Close()
This first uses the HasRows property to determine if there are any rows, and then uses the Read method
to read a row. This is done within a loop, with
Read returning the True if there is a current row and
moving onto the next, and
False if there are no rows.
Summary
The end results of the examples in this chapter have been relatively simple, but you've actually learned a
lot. The first three main topics looked at how to use the Web Matrix to reduce your development time,
taking away much of the legwork you'd normally have to do. We looked at the using the
Data Explorer to
drag and drop tables directly onto page, using the Web Matrix template pages, and using the code wiz-
ards.
After looking at the quick way of getting data, we looked at the theory behind it, examining the objects.
Even though we still continued to use the wizards to generate code, we were now able to see how this
wizard code worked (just because we understand how it works doesn't mean we abandon anything that
makes our job easier.).
Now it's time to look at taking your data usage one step further by showing how to update data, and
how to manage your data handling routines.
Exercises
1. In this chapter we created a page that showed only the products for a selected category. Try and
think of ways to enhance this to show products for either a selected category or all categories.
2. In Exercise 1 we wanted to bind data from a database to a DropDownList as well as manually
add an entry. There are two ways to solve this issue – using techniques shown in this chapter,
and using techniques not yet covered. Try and code the solution using the known technique, but
see if you can think of a way to solve it using a new technique.
286
Chapter 8
57076_Ch 8 SAN.qxd 01/12/2003 6:43 PM Page 286