CSharp.Net-Informations.com
   Home      .Net Framework      VB.NET      C#                                                                      About


  C# ADO.NET OleDbDataAdapter

The OleDbDataAdapter is a part of the C# ADO.NET Data Provider and it resides in the System.Data.OleDb namespace. The OleDbDataAdapter provides the communication between the Dataset and the OleDb Data Sources. We can use OleDbDataAdapter Object in combination with Dataset Object. DataAdapter provides this combination by mapping Fill method, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet.

  OleDbDataAdapter oledbAdapter = new OleDbDataAdapter(sql, oledbCnn);

oledbAdapter.Fill(ds);

The OleDbDataAdapter Object and DataSet objects are combine to perform both Data Access and Data Manipulation operations in the OleDb Data Sources. When the user perform the SQL operations like Select , Insert etc. in the data containing in the Dataset Object , it won't directly affect the Database, until the user invoke the Update method in the OleDbDataAdapter.

         C# Source Code Download           Print Source Code
         C# ADO.NET OleDbDataAdapter - Download
        
C# Tutorial

using System;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb; 

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connetionString = null;
            OleDbConnection oledbCnn ;
            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 like Select * from product"; 

            oledbCnn = new OleDbConnection(connetionString);
            try
            {
                oledbCnn.Open();
                oledbAdapter = new OleDbDataAdapter(sql, oledbCnn);
                oledbAdapter.Fill(ds);
                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]);
                }
                oledbAdapter.Dispose();
                oledbCnn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Can not open connection ! ");
            }
        }
    }
}



C# ADO.NET data Providers Related Contents
*     C# ADO.NET Connection
*     C# SQl Server Connection
*     C# OLEDB Connection
*     C# ODBC Connection
*     C# ADO.NET Command
*     C# ADO.NET SqlCommand - ExecuteNonQuery
*     C# ADO.NET OleDbCommand - ExecuteNonQuery
*     C# ADO.NET SqlCommand - ExecuteScalar
*     C# ADO.NET OleDbCommand - ExecuteScalar
*     C# ADO.NET SqlCommand - ExecuteReader
*     C# ADO.NET OleDbCommand - ExecuteReader
*     C# ADO.NET DataReader
*     C# ADO.NET SqlDataReader
*     C# ADO.NET OleDbDataReader
*     C# Multiple Result Sets
*     C# Table Schema from SqlDataReader
*     C# Table Schema from OleDbDataReader
*     C# ADO.NET DataAdapter
*     C# ADO.NET SqlDataAdapter
*     C# ExecuteReader and ExecuteNonQuery


   Home      VB.NET      C#
CSharp Related Topics
*     An overview of Microsoft CSharp
*     C# Language Tutorial
*     C# Statements Tutorial
*     C# Collection Tutorial
*     C# String Tutorial
*     C# File Operations Tutorial
*     C# Excel Tutorial
*     C# Crystal Reports Tutorial
*     CSharp Communication Tutorial
*     C# Ado.Net Tutorial and Source Code
*     C# ADO.NET data Providers Tutorial
*     C# Dataset Tutorial
*     C# DataAdapater Tutorial
*     Csharp DataView Tutorial
*     Csharp Remoting Tutorial
*     C# XML Tutorial
*     C# DataGridView Tutorial
   Home      VB.NET      C#
More Source Code :   
Mail to :  feedback@net-informations.com
  |  Home   |  VB.NET   |  C#   |  SiteMap   |  Terms of Use   |  About   |
net-informations.com (C) 2010
All Rights Reserved. All other trademarks are property of their respective owners.