Design and Development > .NET Development

need answer

(1/2) > >>

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:

--- Quote ---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 ?
--- End quote ---




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.

Navigation

[0] Message Index

[#] Next page

Go to full version