By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,224 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

retrieve all records from table using OleDbConnection

P: 553

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

Jun 22 '09 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,731
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
  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.

Jun 26 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.