Dataadapter with dataset - OLEDB Data Source

The OleDbDataAdapter serves as a crucial intermediary, facilitating seamless communication between the Dataset and the Data Source through the utilization of the OleDbConnection Object. The OleDbConnection Object does not possess any inherent knowledge regarding the data it retrieves. Similarly, the Dataset is unaware of the specific Data Source from which the data originates. Thus, it is the responsibility of the OleDbDataAdapter to effectively manage the communication and coordination between these two distinct entities.

One of the primary functionalities of the OleDbDataAdapter is to populate Data Tables within a Dataset. This is accomplished by utilizing the Fill method provided by the OleDbDataAdapter. By invoking the Fill method, we can effortlessly retrieve data from the Data Source using the OleDbConnection object and populate the acquired data into the appropriate Data Tables within the Dataset.

To illustrate this process, consider the following source code snippet, which demonstrates a simple program utilizing the OleDbDataAdapter to retrieve data from a Data Source. The program employs the OleDbConnection object to establish a connection with the Data Source and utilizes the Fill method to populate the retrieved data into the relevant Data Tables within the Dataset.

Full Source VB.NET
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 connection As OleDbConnection Dim oledbAdapter As OleDbDataAdapter Dim ds As New DataSet Dim i As Integer connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;" connection = New OleDbConnection(connetionString) Try connection.Open() oledbAdapter = New OleDbDataAdapter("Your SQL Statement Here") oledbAdapter.Fill(ds) oledbAdapter.Dispose() connection.Close() For i = 0 To ds.Tables(0).Rows.Count - 1 MsgBox(ds.Tables(0).Rows(i).Item(0)) Next Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class