Connecting Tech Pros Worldwide Forums | Help | Site Map

retrieve all records from table using OleDbConnection

Site Addict
 
Join Date: Feb 2007
Posts: 553
#1: Jun 22 '09
Hi

Like we can retreive all the records from a table using this method:

While (Not rst.EOF)
....
End While


How to retrieve all the records when using OleDbConnection

Thanks
qi

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,719
#2: Jun 26 '09

re: retrieve all records from table using OleDbConnection


Please take the time to read over the following 2 quick articles on how to use a database in your program:
There are a couple of different controls that you can use to retrieve the data from the database. One of these controls is the OleDbReader...which is returned by the OleDbCommand.ExecuteReader method.

Here's an example (taken from MSDN):
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub ReadMyData(myConnString As String)
  3.     Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
  4.     Dim myConnection As New OleDbConnection(myConnString)
  5.     Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
  6.     myConnection.Open()
  7.     Dim myReader As OleDbDataReader
  8.     myReader = myCommand.ExecuteReader()
  9.     ' Always call Read before accessing data.
  10.     While myReader.Read()
  11.         Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
  12.            + myReader.GetString(1))
  13.     End While
  14.     ' always call Close when done reading.
  15.     myReader.Close()
  16.     ' Close the connection when done with it.
  17.     myConnection.Close()
  18. End Sub
If you don't like this solution, you could always use the OleDataAdapter to fill a DataSet instead.

-Frinny
Reply