Net-informations.com
SiteMap  | About    

ADO.NET ExecuteReader in OleDbCommand Object

ExecuteReader() in OleDbCommand Object send the SQL statements to Connection Object and populate a OleDbDataReader Object based on the SQL statement. When the ExecuteReader method in OleDbCommand Object execute , it instantiate a OleDb.OleDbDataReader Object.

The OleDbDataReader Object is a stream-based , forward-only, read-only retrieval of query results from the Data Source, which do not update the data. The OleDbDataReader cannot be created directly from code, they created only by calling the ExecuteReader method of a Command Object.




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 cnn As OleDbConnection
        Dim cmd As OleDbCommand
        Dim sql As String
        Dim reader As OleDbDataReader

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

        cnn = New OleDbConnection(connetionString)
        Try
            cnn.Open()
            cmd = New OleDbCommand(sql, cnn)
            reader = cmd.ExecuteReader()
            While reader.Read()
                MsgBox(reader.Item(0) & "  -  " & reader.Item(1) & "  -  " & reader.Item(2))
            End While
            reader.Close()
            cmd.Dispose()
            cnn.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) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.