top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is the difference between Command and CommandBuilder object ?

+2 votes
What is the difference between Command and CommandBuilder object ?
posted Apr 23, 2014 by Muskan

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

1 Answer

0 votes
Best answer

I am assuming this to be SQLCommand and SQLCommand Builder:

The SQLCommand Object is used to executes SQL statements and Stored Procedures against the data source. It execute all kind of SQL queries like Insert, update etc.

SqlCommand cmd = new SqlCommand("your sql statements", Connection);

The SqlCommandBuilder can be used to build and execute SQL queries based on the select command that you will supply. It provides the feature of reflecting the changes made to a DataSet or an instance of the SQL server data. The CommandBuilder opens the Connection associated with the DataAdapter Object and makes a round trip to the server each and every time and it's asked to construct the action queries.

The SqlCommandBuilder object acts as a listener for RowUpdating events, whenever the DataAdapter property is set. You can create a SqlCommandBuilder object to automatically generate SQL statements for single table updates if you set the SelectCommand property of the SqlDataAdapter.


SqlDataAdapter  adapter = new SqlDataAdapter("your sql statement", connection);
SqlCommandBuilder  cmdBuilder = new SqlCommandBuilder(adapter);
//Here you can do any modification to the selected data
ds.Tables[0].Rows[i].ItemArray[2] = Convert.ToInt32 (ds.Tables[0].Rows[i].ItemArray[2]) + 100;
//Here save the data to the datasource

The above code select data from database and update it with the help of SqlCommandBuilder object and saves back to the datasource.


answer Apr 27, 2014 by Salil Agrawal
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.