| Using ADO .NET - Access and OleDB Part 2 | |||||||||||||||||||||
| 5 - Finishing the Application | |||||||||||||||||||||
DataReader provides a series of methods to access column values in their native data types (GetDateTime, GetDouble, GetGuid, GetInt32, and so on). These typed accessor methods give you better performance by returning a value as a specific .NET Framework type and don't require additional type conversion. (If you want to see the whole list, Microsoft provides it here.) Here's the same statement using a typed accessor method. (The value 2 indicates that the field is in the second zero based ordinal reference of the column. Or, in other words, it's the third field.) dteAboutVBDate(I) = odtrAboutVBDataReader.GetDateTime(2) The downloaded program has statements for both methods so you can try both on your own (one set is commented out). Finally, the DataReader and the Connection are both closed. .NET is pretty forgiving if you forget (and you see lots of examples - even in books! - where it isn't done) but Microsoft "officially" recommends it: While a DataReader is open, the Connection is in use exclusively by that DataReader. You will not be able to execute any commands for the Connection, including creating another DataReader, until the original DataReader is closed. The rest of the Form Load subroutine is simple housekeeping. The arrays are resized to minimize memory use and the top item in the ListBox is selected. Once this is done, an event subroutine to change the Text properties of the Label components is simple and straightforward. The next page shows the complete program and an example showing it in use. Next page > The Application Example Code > Page 1, 2, 3, 4, 5, 6 |
|||||||||||||||||||||

