.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

difference between ExecuteQuery and ExecuteNonQuery

Posted By: Shweta     Posted Date: June 01, 2010    Points:2   Category :C#
Hi,

I would like to know the difference between ExecuteQuery and ExecuteNonQuery in C#.

Thanks,
Shweta

Responses
Author: BangaruBabuPureti             
Posted Date: June 01, 2010     Points: 5   

ExecuteQuery()------> To Execute SELECT Statement

ExecuteNonQuery()--------> To Execute Other Than Select Statement(means to Execute INSERT/UPDATE/DELETE)

BangaruBabu Pureti
http://bangarubabupureti.spaces.live.com/
Author: Syed Shakeer Hussain             
Posted Date: June 01, 2010     Points: 5   

Hi shweta,
1)ExecuteQuery():-
Executes a SQL-Statement on the Database.
2)ExecuteNonQuery():- The ExecuteNonQuery() is one of the most frequently used method in SqlCommand Object, and is used for executing statements that do not return result sets (ie. statements like insert data , update data etc.) .

Command.ExecuteNonQuery();

The ExecuteNonQuery() performs Data Definition tasks as well as Data Manipulation tasks also. The Data Definition tasks like creating Stored Procedures ,Views etc. perform by the ExecuteNonQuery() . Also Data Manipulation tasks like Insert , Update , Delete etc. also perform by the ExecuteNonQuery() of SqlCommand Object.

The following C# example shows how to use the method ExecuteNonQuery() through SqlCommand Object


SqlConnection cnn = new SqlConnection(connetionString);
cnn.Open();
SqlCommand cmd = new SqlCommand("insert into tablename(id,name) values(11,'dotnetspark')", cnn);
cmd.ExecuteNonQuery();




Author: Lalij Mer             
Posted Date: June 01, 2010     Points: 5   

ExecuteQuery() is for command objects i.e., this method will send "select statement" to database and returns value given by the database.

Moreover the executeQuery() is not used in .net but it is used in JAVA.

ExecuteNonQuery() uses the "Insert/Update/Delete/Stored subprogram" , this method will return number of records effected by the database table


show here more details


http://viralsarvaiya.wordpress.com/2009/12/01/difference-between-executequery-and-execute-nonquery/

Please Check my answer if you help....
Thank You...

Lalit.


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend