what is execute scalar?

Answer Posted / yograj pandey

Use the ExecuteScalar method to retrieve a single value (for example, an aggregate value) from a database. This requires less code than using the ExecuteReader method, and then performing the operations that you need to generate the single value using the data returned by a SqlDataReader.

A typical ExecuteScalar query can be formatted as in the following C# example:

cmd.CommandText = "SELECT COUNT(*) FROM dbo.region";
Int32 count = (Int32) cmd.ExecuteScalar();

Is This Answer Correct ?    6 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can we load multiple tables in to dataset?

824


How to perform sorting on a table in ADO.NET?

786


Explain how can we load multiple tables in to dataset?

723


What are the different ado.net namespaces are available in .net?

772


What is connection in ado.net?

730


What is the difference between linq and ado.net?

750


How to create dynamic gridview?

807


What is a serialized object?

742


What is XML serialization

789


What is basic use of data view?

755


How to copy the contents from one table to another table and how to delete the source table in ado.net?

773


Define connection string?

806


What are dataproviders?

754


What does ado stand for?

712


How to maintain the relation between two tables in ADO.NET?

781