Retrieving Data from an Access Database

by Admin 6. October 2009 21:35

There are a number of easy ways to programmatically retrieve data from an Access database in .NET. The DataReader object is one of the easiest, especially when you need to loop through the data being returned to carry out some calculation or function.

The first step is to create and open a connection to the database using the technique shown in a previous post.

'declare a DataReader

Dim dr As OleDbDataReader 'For an Access database

 

'populate the datareader with the results of the command

dr = cmd.ExecuteReader()

 

'create a loop to read values from the datareader

While dr.Read()

'gain access to the fields using something like below

Dim strValue As String = dr(fieldname).ToString()

End While

 

'close the read when done

dr.Close()

 

Tags: , ,

Access