How to DataAdapter in OLEDB

The OleDbDataAdapter acts as the intermediary between the Dataset and the Data Source by utilizing the OleDbConnection Object for communication. The OleDbConnection Object does not possess information about the retrieved data, just as the Dataset is unaware of the Data Source from which the data originates. Hence, the OleDbDataAdapter manages the seamless communication between these two objects.


The OleDbDataAdapter is instrumental in retrieving data from a data source and populating tables within a Dataset. It also facilitates the synchronization of changes made to the Dataset back to the original data source. By utilizing the Fill method of the OleDbDataAdapter, Data Tables within a Dataset can be populated effectively. The provided C# Source Code illustrates a simple program that employs the OleDbDataAdapter to retrieve data from a Data Source, utilizing the OleDbConnection object, and subsequently populating the retrieved data within a Dataset.

Full Source C#
using System; using System.Data; using System.Data.OleDb; using System.Windows.Forms; namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string connetionString = null; OleDbConnection connection ; OleDbDataAdapter oledbAdapter ; DataSet ds = new DataSet(); int i = 0; connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"; connection = new OleDbConnection(connetionString); try { connection.Open(); oledbAdapter = new OleDbDataAdapter("select * from users", connection); oledbAdapter.Fill(ds); oledbAdapter.Dispose(); connection.Close(); for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { MessageBox.Show (ds.Tables[0].Rows[i].ItemArray[0].ToString ()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }