Divi WordPress Theme

need answer

Topic: need answer  (Read 3085 times)

Offline johndavid

  • Newbie
  • *
  • Posts: 1
  • iTrader: +0/-0
    • View Profile
need answer
« on: June 15, 2009, 01:18:37 PM »
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 ?
VPS Hosting - AccuWebHosting

Offline subhaikav

  • Newbie
  • *
  • Posts: 5
  • iTrader: +0/-0
    • View Profile
Re: need answer
« Reply #1 on: June 25, 2009, 11:25:05 AM »
I too have the same doubt....... Anyone help us?

Offline Kailash

  • Web Hosting Master
  • *****
  • Administrator
  • Posts: 604
  • iTrader: +153/-0
    • View Profile
Re: need answer
« Reply #2 on: June 25, 2009, 11:33:48 AM »
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

Offline mikesleves

  • Newbie
  • *
  • Posts: 3
  • iTrader: +0/-0
    • View Profile
Re: need answer
« Reply #3 on: March 29, 2010, 05:58:23 PM »
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();

Offline StevenJr

  • New Member
  • *
  • Posts: 14
  • iTrader: +0/-0
    • View Profile
Re: need answer
« Reply #4 on: April 09, 2010, 12:32:48 PM »
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 ?




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.

Offline James Andy

  • Junior Guru
  • **
  • Posts: 57
  • iTrader: +0/-0
    • View Profile
Re: need answer
« Reply #5 on: October 03, 2012, 05:09:47 PM »
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.
Divi WordPress Theme
Tags: