retrieve all records from table using OleDbConnection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • questionit
    Contributor
    • Feb 2007
    • 553

    retrieve all records from table using OleDbConnection

    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
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    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.Ex ecuteReader method.

    Here's an example (taken from MSDN):
    Code:
     
    Public Sub ReadMyData(myConnString As String)
        Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
        Dim myConnection As New OleDbConnection(myConnString)
        Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
        myConnection.Open()
        Dim myReader As OleDbDataReader
        myReader = myCommand.ExecuteReader()
        ' Always call Read before accessing data.
        While myReader.Read()
            Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
               + myReader.GetString(1))
        End While
        ' always call Close when done reading.
        myReader.Close()
        ' Close the connection when done with it.
        myConnection.Close()
    End Sub
    If you don't like this solution, you could always use the OleDataAdapter to fill a DataSet instead.

    -Frinny

    Comment

    Working...