473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

stored procedure and return value

Hey

..NET 2.0

I have a stored procedure which calculates a value and return that value.

I'm wondering if I should use ExecuteNonQuery, ExecuteScalar or
ExecuteReader on this stored procedure. I want that return value from the
stored procedure. AFAIK I can use ExecuteReader, but maybe the other options
are much better?

any suggestions?

Jeff
Nov 12 '07 #1
4 4692
Any are fine; the return value is actually used by adding a parameter
to the command with the direction of ReturnValue. After you have
executed the proc, you can obtain the return value via .Value. Note,
however, that if you use ExecuteReader etc (i.e. rows are involved)
then you must walk all the data before you can get out/return values,
since they are positioned at the end of the data-stream.

Marc

Nov 12 '07 #2
I forgot to say, but in general ExecuteNonQuery is a better option if
you don't expect data, simply because it can perform some
optimisations internally. This might have been your real question...

Marc

Nov 12 '07 #3
For me ExecuteScalar will be better, because u can get the return value from
this method rather being depend on output parameter

"Marc Gravell" wrote:
Any are fine; the return value is actually used by adding a parameter
to the command with the direction of ReturnValue. After you have
executed the proc, you can obtain the return value via .Value. Note,
however, that if you use ExecuteReader etc (i.e. rows are involved)
then you must walk all the data before you can get out/return values,
since they are positioned at the end of the data-stream.

Marc

Nov 12 '07 #4
Vivek expressed precisely :
For me ExecuteScalar will be better, because u can get the return value from
this method rather being depend on output parameter
Note: ExecuteScalar will not return the value that is supplied with the
"return" statement in the stored procedure, it will return the first
value of the first row of data. So to use this you need to "select" the
value, not "return" it.

Hans Kesting

"Marc Gravell" wrote:
>Any are fine; the return value is actually used by adding a parameter
to the command with the direction of ReturnValue. After you have
executed the proc, you can obtain the return value via .Value. Note,
however, that if you use ExecuteReader etc (i.e. rows are involved)
then you must walk all the data before you can get out/return values,
since they are positioned at the end of the data-stream.

Marc


Nov 12 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: C Kirby | last post by:
In SQL Server 2000, I've got a rather lengthy stored procedure, which creates a lot of temporary tables as it processes down through a few sets of data. When testing it through Query Analyzer, it...
0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
5
by: Sandy | last post by:
Hello - I need a good example of how to take a return value from a stored procedure and use it in vb code. I have an app that searches a database by city and state. If a user makes a typo, the...
7
by: Siv | last post by:
Hi, I have a stored procedure that I want to execute and then wait in a loop showing a timer whilst it completes and then carry on once I get notification that it has completed. The main reason...
4
by: nishi57 | last post by:
I hope I can get some help regarding this issue, which has been going on for a while. I have a desktop user who is having problem running "Stored Procedures". The DB2 Connect application works fine...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL2000 database. I have a stored procedure called "INSERT_INTO_MYTABLE" that accepts 1 parameter (varchar(10)) and returns the identity column value from that table....
9
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug...
12
by: Dooza | last post by:
I have a stored procedure that takes a number of inputs, does a bulk insert, and then outputs a recordset. When I run the stored procedure in Server Management Studio I also get a return value from...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.