Buy Questpond's video subscriptions on
huge discount
.
Online: 845
Home
Articles
Interviews
Forums
For Beginners
Popular Questions
ITIL Career Advice
PMP Career Advice
Career Advices
Codes
Videos
ASP.NET
ASP.NET MVC
Android Intel XDK
Sql Server
AngularJS
Bootstrap
Backbone.JS
MongoDB
LESS (CSS)
jQuery
WPF
WWF
SSIS
LightSwitch
Tutorials
News
ASP.NET MVC
|
Be Interview Ready
|
Top Performers
|
DNF MVP
|
Top Posts
|
Winners
|
Subscribe
|
Catalogs
Welcome Guest !
Register
Login
Home
>
Articles
>
ADO.NET
>
Loading ...
Post
An Article
An Interview Question
A Forum Post
A Career Advice Question
A Video
A Code
A Job
A Product Catalog
An Interview Experience
A Bookmark
A News
How to use ExecuteScalar() method
Posted by
Zinnia Sarkar
in
ADO.NET
category on
1/31/2011
for Beginner level |
Points: 250
| Views : 88569
X
If you found
plagiarised (copied)
or inappropriate content,
please
let us know
the original source along with your correct email id (to communicate) for further action.
Rating:
3
out of 5
3
vote(s)
Post Article
|
Search Articles
|
Articles Home
This article is describing the use of ExecuteScalar() method.
Introduction
We can use ExecuteScalar() method, if we have to retrieve a single value from a database. It executes the query and returns the first column of the first row in the result set returned by the query. Additional rows and columns are simply discarded. It returns a maximum of 2033 characters. It is better to get the result of MAX,MIN,COUNT, etc using ExecuteScalar() method.
Benefit
1. ExecuteScalar() requires the less code than using ExecuteReader().
2. ExecuteScalar() immediately returns the actual value. Hence, in case of retrieving single value from a database, it is fast and efficient.
INSERT
The following figure shows the records inserted using cmd.ExecuteScalar() method.
MAX
MIN
COUNT
Returns an object type
ExecuteScalar() method returns an object type.
So when i m trying to initialize the result of cmd.ExecuteScalar() method in an integer variable, it is giving the below given error.
Conclusion
Happy Reading!
Reference
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
About the Author
Full Name:
Zinnia Sarkar
Member Level:
Member Status: Member
Member Since: 7/24/2010 12:50:40 PM
Country: India
Regards, Ganeshji
Bookmark It
Login
to vote for this post.
Latest Articles
How to copy or move Excel worksheets in C#
How to convert PDF to Excel and PDF to Word in C#/VB.NET
How to host ASP.NET Core 3.x MVC application on server
How to publish .NET Core 3.x MVC application from Visual Studio 2019
Same action method and different parameters in .NET core
More Articles ...
Latest Articles from Ganeshji
Dataadapter.Fill() Method can be overloaded in 5 different ways.
ASP.NET 4.0 Routing
Static Keyword in C#
Multiple Inheritance in C#
An Interface in C#
More articles from Ganeshji
Comments or Responses
Posted by:
Seenuvasan
on: 6/10/2011 |
Points: 25
nice article ganeshji
Posted by:
Ganeshji
on: 6/10/2011 |
Points: 25
Thnx Seenuvasan!
Posted by:
Akiii
on: 8/16/2011 |
Points: 25
good article zinnia...
Thanks and Regards
Akiii
Posted by:
Ganeshji
on: 8/17/2011 |
Points: 25
Thnx Akii!
Posted by:
Ksuresh
on: 12/26/2011 |
Points: 25
Good Article and Thanx for in solving my problem....
Posted by:
Ganeshji
on: 12/26/2011 |
Points: 25
Thnx Ksuresh! Keep reading!
Posted by:
Shameer.Ali87
on: 6/6/2012 |
Points: 25
nice article Ganeshji....
Posted by:
Sangeetha Mani
on: 3/4/2013 |
Points: 25
hi ,
thanks for posting this article.. but i have confused .. actually execute scalar method for aggregate function. then why should you using insert command .. ?
Posted by:
Reze12
on: 4/18/2019 |
Points: 25
Good Article and Thanx for in solving my problem....
https://www.augenus.com/
Login to post response
Comment using
(Author doesn't get notification)