Connecting Tech Pros Worldwide Help | Site Map

retrieve all records from table using OleDbConnection

  #1  
Old June 22nd, 2009, 07:52 AM
Site Addict
 
Join Date: Feb 2007
Posts: 553
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
  #2  
Old June 26th, 2009, 07:47 PM
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North :)
Posts: 4,940
Provided Answers: 8

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem Retrieving From Excel in C# xia0jie answers 1 October 14th, 2009 03:46 PM
How to access one value from a Excel sheet using a SQL statement and C# pitchblack408 answers 4 January 9th, 2008 12:21 AM
what am I doing wrong ? SLIMSHIM answers 16 November 13th, 2006 10:15 AM
I want to create a database and store and retrieve information Roy Gourgi answers 5 November 17th, 2005 11:15 AM