PC Review


Reply
Thread Tools Rate Thread

Confused with ExecuteScalar method of SQLCommand

 
 
=?Utf-8?B?RGluZXNo?=
Guest
Posts: n/a
 
      22nd Mar 2005
Hi,
I have one stored procedure in SQL server in which i have written one
insert statement. Now in my cs file i pass the parameters require to execute
that stored procedure and finaly by mistaken I used command.ExecuteScalar
instead of command.ExecuteNonQuery. Surprisingly i am able to insert the data
in table. Can anyone please tell me how i am able to insert data using
ExecuteScalar of SQLCommand class.

Help is really appriciated.

Thx in advance
 
Reply With Quote
 
 
 
 
Steven Lewis
Guest
Posts: n/a
 
      22nd Mar 2005
Hi there,

ExecuteScalar return the first row's first column. The rest is ignored.
ExecuteNonQuery returns the number of records afected by your query.

You can insert the data because it is in a stored procedure, and I haven't
tested it, but maybe you could ExecuteScalar with an insert statement as
well with a select statement..

Best regards

Steven Lewis


"Dinesh" <(E-Mail Removed)> escribió en el mensaje
news:28CD733C-7D7A-4C0F-8D0F-(E-Mail Removed)...
> Hi,
> I have one stored procedure in SQL server in which i have written one
> insert statement. Now in my cs file i pass the parameters require to
> execute
> that stored procedure and finaly by mistaken I used command.ExecuteScalar
> instead of command.ExecuteNonQuery. Surprisingly i am able to insert the
> data
> in table. Can anyone please tell me how i am able to insert data using
> ExecuteScalar of SQLCommand class.
>
> Help is really appriciated.
>
> Thx in advance



 
Reply With Quote
 
Chris Priede
Guest
Posts: n/a
 
      22nd Mar 2005
Dinesh wrote:
> Surprisingly i am able to insert the data in table. Can anyone please
> tell me how i am able to insert data using ExecuteScalar of
> SQLCommand class.


ExecuteScalar() can execute anything. Should your query return any rows of
data, it will return the value in the first column of the first returned
row; should it not, it will return null.

This should not be surprising if you consider the fact SELECT isn't
guaranteed to return data either -- it is quite normal for a query to match
no rows.


--
Chris Priede ((E-Mail Removed))


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: SqlCommand.ExecuteScalar Returning XML Data Lloyd Sheen Microsoft Dot NET Framework 0 20th Aug 2004 04:34 PM
Re: SqlCommand.ExecuteScalar Returning XML Data Jon Brunson Microsoft Dot NET Framework 0 20th Aug 2004 03:20 PM
sqlCommand.ExecuteScalar return value 'undefined value' RA Microsoft ADO .NET 2 5th Dec 2003 01:33 AM
sqlCommand.ExecuteScalar problem on return value RA Microsoft ADO .NET 3 4th Dec 2003 03:17 PM
executescalar() method buran Microsoft ADO .NET 5 23rd Jul 2003 02:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:10 AM.