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.c-sharpcorner.com/blogs/executereader-executenonquery-and-executescalar-in-adonet
No comments:
Post a Comment