• Welcome to Web Hosting Community Forum for Webmasters - Web hosting Forum.
 

Recommended Providers


Jetpack
Fully Managed WordPress Hosting
lc_banner_leadgen_3
Fully Managed WordPress Hosting

WordPress Theme

WordPress Hosting Divi WordPress Theme
WPZOOM

Forum Membership

Forum Membership

need answer

Started by johndavid, June 15, 2009, 01:18:37 PM


WordPress Hosting


johndavid

hi friend i am having one doubt in dotnet so if anyone can able to help pls

this is my doubt
What is the purpose of Execute scalar method of Command object ?

subhaikav

I too have the same doubt....... Anyone help us?

Kailash

Hi,

Welcome to the forum!

I am not good in .Net but I found one useful msdn link for ExecuteScalar Method:

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

Hope this will help you.

Kailash

mikesleves

When a query return single value from database, The ExecuteScalar Method is used. In such cases Sql Statements like Finding no of records, finding Maximum value from table. And then performing the operations necessary to generate the single value. Other Columns Value or rows are ignored.

This would be easy for receiving a records in an sql statement, or for any query where only one specific field in one column is needed.
cmd.CommandText = "select count(*) from projects";
Int32 count1 = (int32) cmd.ExecuteScalar();

StevenJr

Quotehi friend i am having one doubt in dotnet so if anyone can able to help pls
this is my doubt
What is the purpose of Execute scalar method of Command object ?




Hi John,

The "ExecuteScalar" method is used to retrieve a single value from the database. This requires less code than using the "ExecuteReader" method which is used to generate a single value through data returned by SqlDataReader. The method is fast and utilizes less resources from the database.
Setup your own home business  to earn a lot

James Andy

Always use ExecuteNonQuery except: when you have a set of records - use ExecuteReader and when you have a single output value that cannot be defined as a parameter - use ExecuteScalar. Hope this helped to clarify something.