Why SqlCommandBuilder is used ? [Resolved]

Posted by Akiii under C# on 5/5/2011 | Points: 10 | Views : 20713 | Status : [Member] | Replies : 5
Hi,
Please can anyone tell me why SqlCommandBuilder is used ?
It is taking SqlDataAdapter as an argument but why will one use it?

Thanks and Regards
Akiii




Responses

Posted by: SheoNarayan on: 5/5/2011 [Administrator] HonoraryPlatinum | Points: 50

Up
0
Down

Resolved
This should be the answer of your question http://www.dotnetfunda.com/interview/exam3750-what-is-the-use-of-sqlcommandbuilder-.aspx, good explanations by Dinesh.

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nishithraj on: 5/5/2011 [Member] Bronze | Points: 50

Up
0
Down

Resolved
To know this you should understand the difference between SqlCommand and SqlCommandBuilder .

A Command object is used to execute scalar or non query commands to a database. You would set a command objects CommandText property to and sql statement that you want to run and then use it's ExecuteScalar or ExecuteNonQuery method to run it.

A CommandBuilder object is used to automatically create Update, Delete, and Insert SQL statements for you, based on a Select statament that you supply. You would declare a DataAdapter object, set it's SelectCommand.CommandText property to your Select SQL statement. Then when you declare a CommandBuilder object, you include the dataadapter in the CommandBuilder's constructor parameter and it will automatically create the other statements for you when you run a DataAdapter.

In the above link, dataset changes are updated permanently by the code

//save the Row permanently 

da.Update(dt);


This is done without writing any update queries, You got it???




Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/5/2011 [Member] Bronze | Points: 25

Up
0
Down
Thanks sir for the reply...

i have seen that post but cant we use insert,update and delete stmts without the use of SqlCommandBuilder ?

Thanks
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Akiii on: 5/5/2011 [Member] Bronze | Points: 25

Up
0
Down
Thanks nishithraj......
very good explanation..........

Thanks to you and Sheo sir for making me understand......!

Regards
Akiii

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Shivangkaul on: 11/15/2012 [Member] Starter | Points: 25

Up
0
Down
Hey Guys! its good that SqlCommandBuilder generates the queries internally for Update, Insert and other operations but what is the benefit of using it in the enterprise applications where all the CRUD operations are defined in Stored Procedures????

Akiii, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response