SiteMap  | About    

How to DataAdapter Update Command - Sql Server

SqlDataAdapter is a part of the ADO.NET Data Provider. The SqlDataAdapter 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 SqlDataAdapter Object update the database with the data modifications, that are run on a DataSet object.

The following C# code samples demonstrate how to use the SqlDataAdapter object to update a SQL Server database using UpdateCommand properties .

using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace WindowsApplication1
    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            string connetionString = null;
            SqlConnection connection ;
            SqlDataAdapter adapter = new SqlDataAdapter();
            string sql = null;
            connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
            connection = new SqlConnection(connetionString);
            sql = "update product set product_price = 1001 where Product_name ='Product6'";
                adapter.UpdateCommand = connection.CreateCommand();
                adapter.UpdateCommand.CommandText = sql;
                MessageBox.Show ("Row updated !! ");
            catch (Exception ex)
} (C) 2015    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.