Click here to Skip to main content
15,886,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can you tell me the return types for execute scalar and execute reader and execute non query
Posted
Comments
Member 11443915 25-Feb-15 0:17am    
what use public class in asp.net mvc

ExecuteNonQuery: Use this operation to execute any arbitrary SQL statements in SQL Server if you do not want any result set to be returned.

You can use this operation to create database objects or change data in a database by executing UPDATE, INSERT, or DELETE statements. The return value of this operation is of Int32 data type, and:
For the UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the SQL statement.

For all other types of statements, the return value is -1.

ExecuteReader: Use this operation to execute any arbitrary SQL statements in SQL Server if you want the result set to be returned, if any, as an array of DataSet.
For information about DataSet, see “DataSet Class” at http://go.microsoft.com/fwlink/?LinkId=119631.[^]
(e.g., SELECT col1, col2 from sometable).

ExecuteScalar: Use this operation to execute any arbitrary SQL statements in SQL Server to return a single value.
This operation returns the value only in the first column of the first row in the result set returned by the SQL statement.
An example might be SELECT @@IDENTITY AS 'Identity'.

Refer similar thread:
What is the difference between Execute Scalar , Execute Reader and ExecuteNonQuery[^]
What is the difference between ExecuteNonQuery, ExecuteReader, and ExecuteScalar?[^]

MSDN:
http://msdn.microsoft.com/en-us/library/dd787963(v=bts.10).aspx[^]
http://msdn.microsoft.com/en-us/library/dd788418(v=bts.10).aspx[^]
 
Share this answer
 
Comments
Rahul Rajat Singh 27-Jun-12 0:36am    
good answer. +5.
Prasad_Kulkarni 27-Jun-12 0:38am    
Thank you Rahul!
ExecuteNonQuery(): will work with Action Queries only (Create,Alter,Drop,Insert,Update,Delete).

Returns the count of rows effected by the Query.
Return type is int
Return value is optional and can be assigned to an integer variable.

ExecuteReader(): will work with Action and Non-Action Queries (Select) Returns the collection of rows selected by the Query.

Return type is DataReader.
Return value is compulsory and should be assigned to an another object DataReader.

ExecuteScalar(): will work with Non-Action Queries that contain aggregate functions.

Return the first row and first column value of the query result.
Return type is object.
Return value is compulsory and should be assigned to a variable of required type
 
Share this answer
 
Comments
Member 11443915 25-Feb-15 0:16am    
what use public class in asp.net mvc

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900