Wednesday, November 10, 2021

Difference between ExecuteScalar(), ExecuteReader(), ExecuteNONQuery() in ado.net

executescaler, executereader and executenonquery all three are used for executing any query but return types are diffrent.

 ExecuteScaler:- returns the single object or (value of first row of first column)

example:-

int a= Convert.ToInt32(cmd.ExecuteScalar());// but it is giving 0 integer value in insert

>insert and select statement

> for fetching single cell value

--------------------------------------

ExecuteNonQuery :- used for insert, update and delete statement, returns int.(gives integer values of number of records updated) does not use for returning of records. 

ExecuteReader:- used for insert, update and delete and select query

 return set of records.


references:- https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand.executescalar?view=dotnet-plat-ext-6.0

https://www.aspsnippets.com/Articles/ExecuteNonQuery-Insert-Update-and-Delete-examples-in-C-and-VBNet.aspx

https://www.c-sharpcorner.com/blogs/executereader-executenonquery-and-executescalar-in-adonet

https://docs.microsoft.com/en-us/biztalk/adapters-and-accelerators/adapter-sql/executenonquery-executereader-and-executescalar-using-the-sql-adapter

No comments:

Post a Comment