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

Top 5 Contributors of the Month

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#

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


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
Author: Syed Shakeer Hussain             
Posted Date: June 01, 2010     Points: 5   

Hi shweta,
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.) .


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);
SqlCommand cmd = new SqlCommand("insert into tablename(id,name) values(11,'dotnetspark')", cnn);

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


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


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

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