latest Post

Difference Between ExecuteNonQuery and ExecuteScalar ADO.NET

ExecuteNonQuery()

It Returns the count of Rows Effected by the Query.

Int in Return Type.

ExecuteNonQuery() works  Queries only. Create,Alter,Drop,Insert,Update,Delete.

   
Can be assigned to an integer variable.
Return value is optional.

   
SqlCommand cmd=new SqlCommand();
cmd.ExecuteNonQuery();


ExecuteScalar()


It Returns the First Row and First Column Value of the Query.

Object in Return Type.


ExecuteScalar() works Only Aggregate Functions
Max,Min,Count,Sum,Total.

Return value is Compulsory.

SqlCommand cmd=new SqlCommand();
id = (Int16)cmd.ExecuteScalar();

return id;

About Mallikarjun A

Mallikarjun A
Recommended Posts × +

0 comments:

Post a Comment