473,395 Members | 1,823 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,395 software developers and data experts.

calling stored procedure with parameter as reference

VMI
Can I call a stored proc from .net with a parm that changes during the SP?
For example, I call the SP with parameter sMyVariable (which changes in the
SP), and when I access it after the SP is executed, sMyVariable will have the
new value. My solution (if this doesn't exist) would've been to add the
value to the resultset (make it part of the Select statement)

Thanks.
Nov 17 '05 #1
7 2044

"VMI" wrote...
Can I call a stored proc from .net with a parm that changes
during the SP? For example, I call the SP with parameter
sMyVariable (which changes in the SP), and when I access it
after the SP is executed, sMyVariable will have the
new value. My solution (if this doesn't exist) would've been
to add the value to the resultset (make it part of the Select
statement)


AFAIK that depends on what database you're using.

In ADO.NET you can have a Parameter argument with e.g.
ParameterDirection.InputOutput.

This can be used in conjunction with e.g. an "IN OUT" parameter in an Oracle
SP, but AFAIK, SQL Server doesn't have that. It *does* have the possibility
of "OUTPUT" parameters, so you could possibly use that in your SP to return
the new value, though through a second parameter.
// Bjorn A

Nov 17 '05 #2
You don't need a second parameter. You can declare the parameter as
InputOutput for SQL Server (maybe for others as well). I believe you can
also return a set in conjunction with said parameter if you like.

--

Derek Davis
dd******@gmail.com

"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:Oi**************@TK2MSFTNGP14.phx.gbl...

"VMI" wrote...
Can I call a stored proc from .net with a parm that changes
during the SP? For example, I call the SP with parameter
sMyVariable (which changes in the SP), and when I access it
after the SP is executed, sMyVariable will have the
new value. My solution (if this doesn't exist) would've been
to add the value to the resultset (make it part of the Select
statement)


AFAIK that depends on what database you're using.

In ADO.NET you can have a Parameter argument with e.g.
ParameterDirection.InputOutput.

This can be used in conjunction with e.g. an "IN OUT" parameter in an
Oracle SP, but AFAIK, SQL Server doesn't have that. It *does* have the
possibility of "OUTPUT" parameters, so you could possibly use that in your
SP to return the new value, though through a second parameter.
// Bjorn A


Nov 17 '05 #3

"carion1" wrote...
You don't need a second parameter. You can declare the
parameter as InputOutput for SQL Server (maybe for others
as well).


I know it works with Oracle, but is it really true for SPs in SQL Server?

As I have searched for that possibility, I would be happy if you could
provide a link to where I can read about SQL Server having InputOutput
parameters in stored procedures?

// Bjorn A
Nov 17 '05 #4
http://msdn.microsoft.com/library/de...es_07_3q7n.asp

Below is just a quick example:

CREATE proc dbo.usp_test

@test varchar(100) out

as

set @test = @test + ' World!'
GO

--------------------------------

Connection = new SqlConnection();
Connection.ConnectionString = YOUR_CONNECTION_STRING_GOES_HERE
Connection.Open();
Command = new SqlCommand();
Command.Connection = Connection;
Command.CommandType = CommandType.StoredProcedure;
Command.CommandText = "usp_test";
SqlParameter parm = new SqlParameter("@test", "Hello");
parm.Direction = ParameterDirection.InputOutput;
Command.Parameters.Add(parm);
Command.ExecuteNonQuery();
MessageBox.Show(Command.Parameters["@test"].Value.ToString());
Command.Dispose();
Connection.Dispose();

--

Derek Davis
dd******@gmail.com

"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

"carion1" wrote...
You don't need a second parameter. You can declare the
parameter as InputOutput for SQL Server (maybe for others
as well).


I know it works with Oracle, but is it really true for SPs in SQL Server?

As I have searched for that possibility, I would be happy if you could
provide a link to where I can read about SQL Server having InputOutput
parameters in stored procedures?

// Bjorn A

Nov 17 '05 #5
I forgot to specify the size for the parameter:

parm.Size = 100;

--

Derek Davis
dd******@gmail.com

"carion1" <dd******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
http://msdn.microsoft.com/library/de...es_07_3q7n.asp

Below is just a quick example:

CREATE proc dbo.usp_test

@test varchar(100) out

as

set @test = @test + ' World!'
GO

--------------------------------

Connection = new SqlConnection();
Connection.ConnectionString = YOUR_CONNECTION_STRING_GOES_HERE
Connection.Open();
Command = new SqlCommand();
Command.Connection = Connection;
Command.CommandType = CommandType.StoredProcedure;
Command.CommandText = "usp_test";
SqlParameter parm = new SqlParameter("@test", "Hello");
parm.Direction = ParameterDirection.InputOutput;
Command.Parameters.Add(parm);
Command.ExecuteNonQuery();
MessageBox.Show(Command.Parameters["@test"].Value.ToString());
Command.Dispose();
Connection.Dispose();

--

Derek Davis
dd******@gmail.com

"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...

"carion1" wrote...
You don't need a second parameter. You can declare the
parameter as InputOutput for SQL Server (maybe for others
as well).


I know it works with Oracle, but is it really true for SPs in SQL Server?

As I have searched for that possibility, I would be happy if you could
provide a link to where I can read about SQL Server having InputOutput
parameters in stored procedures?

// Bjorn A


Nov 17 '05 #6
"carion1" wrote
"Bjorn Abelli" wrote
As I have searched for that possibility, I would be happy
if you could provide a link to where I can read about SQL
Server having InputOutput parameters in stored procedures?


[snipped code sample]

Thank you!

How I have looked, I haven't seen any documentation on this functionality of
the "output" parameter in T-SQL. It seems that I have been deceived by the
use of "output" as the keyword for what really is an InputOutput parameter!

You never stop to learn... ;-)
// Bjorn A

Nov 17 '05 #7
Glad I could help.

--

Derek Davis
dd******@gmail.com

"Bjorn Abelli" <bj**********@DoNotSpam.hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
"carion1" wrote
"Bjorn Abelli" wrote As I have searched for that possibility, I would be happy
if you could provide a link to where I can read about SQL
Server having InputOutput parameters in stored procedures?


[snipped code sample]

Thank you!

How I have looked, I haven't seen any documentation on this functionality
of the "output" parameter in T-SQL. It seems that I have been deceived by
the use of "output" as the keyword for what really is an InputOutput
parameter!

You never stop to learn... ;-)
// Bjorn A

Nov 18 '05 #8

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

Similar topics

6
by: dw | last post by:
Hello all, I'm having a dickens of a time calling a stored procedure on a connection. Every time I do, it generates an error "Arguments are of the wrong type, are out of acceptable range, or are in...
4
by: Bob Murdoch | last post by:
I have an ASP application that calls a COM function to create a custom report as an Excel file. This works in a synchronous fashion, as long as the report does not take too long to create. If...
18
by: Jarrod Morrison | last post by:
Hi All I was wondering if there is a way to call a stored procedure from inside another stored procedure. So for example my first procedure will call a second stored procedure which when...
5
by: Frank Apap | last post by:
I am trying to call a stored procedure that has an INOUT parameter from the CLP to do some testing on a UDB 8 system. Since the value is needed as input I cannot use ? for the parameter, and...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
4
by: Jack | last post by:
Hi, I am trying to run an example code from a book. However I am getting the following error message: Number: -2147217900 Description: Syntax error or access violation Source: Microsoft OLE...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
3
by: .Net Sports | last post by:
I need to call an stored procedure from an asp script, I don't need to do an Output parameter, only input parameters on 3 vars, but I get a "BOF EOF not true or record has been deleted" error when...
6
Soniad
by: Soniad | last post by:
Hello, I am excecuting a stored procedure in my ASP page , it has one out parameter (@confirm) . after executing the procedure i want to retreive this out parameter and assign it to variable...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.