C# Datset with OLEDB Data Provider

The DataSet in ADO.NET holds a copy of the data retrieved through the SQL statement or query. It represents a comprehensive set of data that includes the tables, their order, constraints, and relationships between the tables.

OleDbDataAdapter Class

When working with the DataSet, you can indeed use it in combination with the OleDbDataAdapter Class. The OleDbDataAdapter facilitates the communication between the data source and the DataSet when using an OLEDB provider.

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(); string sql = null; int i = 0; connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;"; sql = "Your SQL Statement Here"; connection = new OleDbConnection(connetionString); try { connection.Open(); oledbAdapter = new OleDbDataAdapter(sql, 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] + " -- " + ds.Tables[0].Rows[i].ItemArray[1]); } } catch (Exception ex) { MessageBox.Show("Can not open connection ! "); } } } }

To populate the DataTables within the DataSet with data from the data source, you can utilize the OleDbDataAdapter. It provides methods such as Fill() that retrieve data from the data source and populate the DataTables within the DataSet.

The Fill() method of the OleDbDataAdapter retrieves the data from the data source based on the provided SQL statement or query and fills the corresponding DataTables in the DataSet.

Conclusion

Using the combination of the DataSet and OleDbDataAdapter, you can effectively retrieve and store data from the data source into DataTables within the DataSet. This allows for efficient data access, manipulation, and analysis within your C# application using ADO.NET.