1. Home
  2. Computing & Technology
  3. Visual Basic

Chapter 19 - Getting Started With ADO.NET

By , About.com Guide

10 of 10

Page 4 of the program and the conclusion of the lesson

Example Program

Example Program

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 downloadable source code 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.

~~~~~~~~~~~~~~~~~~~~~~~~~
odtrAboutVBDataReader.Close() ocmdAboutVBCommand.Connection.Close()
~~~~~~~~~~~~~~~~~~~~~~~~~

.NET is pretty forgiving if you forget (and you see lots of examples - even in books! - where a "close" 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.

Download the entire source.

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Getting Started with ADO.NET

©2009 About.com, a part of The New York Times Company.

All rights reserved.