Recently I was asked to create a data entry page for a table with 35 columns, 10 of which needed
to be DropDownLists (combo boxes). It seemed very inefficient, and required too many coding key strokes, to
go to the database 10 times to get the values for the DropDownLists. I started looking for a better
way. I did some poking around and came across the NextResult method of the datareader. It turns out
that you can do batch queries (multiple SELECT statements in one string), requiring only one trip to
the database, and then use NextResult to step through each result set to obtain the data.
This requires only one trip to the database and means you do not have to keep resetting the command object
and the datareader for each resultset. I'm rather anal about how my code looks, and I believe using this
technique makes the code "look better".
To illustrate the technique we will select columns from four different tables of the Northwind database.
These columns don't necessarily make any sense application wise, but they will illustrate the technique.
First, the aspx file where we set up our DropDownLists.