Net-informations.com
SiteMap  | About    

How to DataAdapter Update Command - OLEDB

OleDbDataAdapter is a part of the ADO.NET Data Provider. The OleDbDataAdapter uses the Connection object of the .NET Framework data provider to connect to a data source and Command objects to retrieve data from and resolve changes to the data source. The InsertCommand , the UpdateCommand , and the DeleteCommand properties of the OleDbDataAdapter object update the Data Source with the data modifications that are run on a DataSet object.

The following C# code samples demonstrate how to use the OleDbDataAdapter object to update an OLEDB Data Source using UpdateCommand properties .




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 = new OleDbDataAdapter();
            string sql = null;
            connetionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Your mdb filename;";
            connection = new OleDbConnection(connetionString);
            sql = "update Users set Password = 'new password' where UserID = 'user1'";
            try
            {
                connection.Open();
                oledbAdapter.UpdateCommand = connection.CreateCommand();
                oledbAdapter.UpdateCommand.CommandText = sql;
                oledbAdapter.UpdateCommand.ExecuteNonQuery();
                MessageBox.Show ("Row(s) Updated !! ");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}






net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.