Database Reference
In-Depth Information
Let's say you've successfully established a connection with the database, a query has been executed,
and everything seems to be going fine—what now? The next sensible thing to do would be to retrieve the
rows and process them.
Try It: Looping Through a Result Set
The following Windows application shows how to use a SqlDataReader to loop through a result set and
retrieve rows:
1. Create a new Windows Forms Application project named Chapter14. When
Solution Explorer opens, save the solution.
2. Rename the Chapter14 project to DataReader. Rename the Form1.cs file to
DataLooper.cs.
3. Select the DataLooper form by clicking the form's title bar, and set the Size
property's Width to 346 and Height to 476.
4. Drag a ListBox control onto the form, and position it toward the center of the
form. Select this ListBox, navigate to the Properties window, and set the
following properties:
Set the Name property to lbxProduct.
Set the Location property's X to 21 and Y to 22.
Set the Size property's Width to 281 and Height to 394.
5. Now your DataLooper form in the Design view should like Figure 14-1.
 
Search WWH ::




Custom Search