Net-informations.com
SiteMap  | About    

How to ADO.NET OleDbDataReader

OleDbDataReader Object provides a connection oriented data access to the OLEDB Data Sources. ExecuteReader() in the OleDbCommand Object send the SQL statements to OleDbConnection Object and populate an OleDbDataReader Object based on the SQL statement.

Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()

When the ExecuteReader method in OleDbCommand Object execute , it instantiate an OleDb.OleDbDataReader Object. When started to read from an OleDbDataReader it should always be open and positioned prior to the first record. The Read() method in the OleDbDataReader is used to read the rows from OleDbDataReader and it always moves forward to a new valid row, if any row exist .

OleDbDataReader.Read()




Imports System.Data.OleDb
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connetionString As String
        Dim oledbCnn As OleDbConnection
        Dim oledbCmd As OleDbCommand
        Dim sql As String

        connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"
        sql = "Your SQL Statement Here like Select * from product"

        oledbCnn = New OleDbConnection(connetionString)
        Try
            oledbCnn.Open()
            oledbCmd = New OleDbCommand(sql, oledbCnn)
            Dim oledbReader As OleDbDataReader = oledbCmd.ExecuteReader()
            While oledbReader.Read
                MsgBox(oledbReader.Item(0) & "  -  " & oledbReader.Item(1) & "  -  " & oledbReader.Item(2))
            End While
            oledbReader.Close()
            oledbCmd.Dispose()
            oledbCnn.Close()
        Catch ex As Exception
            MsgBox("Can not open connection ! ")
        End Try
    End Sub
End Class

connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"
sql = "Your SQL Statement Here like Select * from product"

You have to replace the string with your realtime variables.





net-informations.com (C) 2016    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.