|
Using ADO .NET - Access and OleDB Part 2 |
|||||||||||||||||||||
| 3 - Coding A DataReader Application | |||||||||||||||||||||
In the example application we will cover here, the entire database is stored in a series of arrays. This allows random access to the data after the connection is closed on the client machine. The entire solution can be downloaded at the end of the article, but first, I'll go through each line of code and explain how it works. The flowchart boxes at the left diagram the ADO .NET related steps visually. The application starts with an Imports statement for the OleDb namespace. Then, before any subroutine code, a series of DIM statements are added to make the scope of the variables global over the subroutines. This has nothing to do with ADO .NET but it makes my program work. The program reads the database and initializes the ListBox in the Form Load subroutine. The first statement in that subroutine is the declaration of the Connection String. This is a set of parameters that allows ADO .NET to match the unique characteristics of your database. For the Access database in this example, the Connection String is pretty simple. (Note that {path} must be replaced by the actual path on the computer.) The next statements declare objects necessary for using OleDb: the Command object and the DataReader object. The Imports statement coded earlier makes it possible to avoid qualifying these names in the DIM statement. Without the Imports statement, OleDbCommand would be coded as System.Data.OleDb.OleDbCommand. The next tasks are to instantiate the Command and Connection objects, Open the Connection and execute the DataReader. But before we do that, another refinement will be added. |
|||||||||||||||||||||

