473,803 Members | 3,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2061

"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.
ParameterDirect ion.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**********@D oNotSpam.hotmai l.com> wrote in message
news:Oi******** ******@TK2MSFTN GP14.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.
ParameterDirect ion.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.Conn ectionString = YOUR_CONNECTION _STRING_GOES_HE RE
Connection.Open ();
Command = new SqlCommand();
Command.Connect ion = Connection;
Command.Command Type = CommandType.Sto redProcedure;
Command.Command Text = "usp_test";
SqlParameter parm = new SqlParameter("@ test", "Hello");
parm.Direction = ParameterDirect ion.InputOutput ;
Command.Paramet ers.Add(parm);
Command.Execute NonQuery();
MessageBox.Show (Command.Parame ters["@test"].Value.ToString ());
Command.Dispose ();
Connection.Disp ose();

--

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

"Bjorn Abelli" <bj**********@D oNotSpam.hotmai l.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.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******** ********@TK2MSF TNGP11.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.Conn ectionString = YOUR_CONNECTION _STRING_GOES_HE RE
Connection.Open ();
Command = new SqlCommand();
Command.Connect ion = Connection;
Command.Command Type = CommandType.Sto redProcedure;
Command.Command Text = "usp_test";
SqlParameter parm = new SqlParameter("@ test", "Hello");
parm.Direction = ParameterDirect ion.InputOutput ;
Command.Paramet ers.Add(parm);
Command.Execute NonQuery();
MessageBox.Show (Command.Parame ters["@test"].Value.ToString ());
Command.Dispose ();
Connection.Disp ose();

--

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

"Bjorn Abelli" <bj**********@D oNotSpam.hotmai l.com> wrote in message
news:%2******** ********@TK2MSF TNGP15.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**********@D oNotSpam.hotmai l.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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
6904
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 conflict with one another." I've run the same stored procedure with the same exact list of arguments in Query Analyser in SQL Server, and it works. The page has the adovbs constants. Note that uspGetProperties is a stored procedure in SQL...
4
5790
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 that happens, the session times out and we run into other kinds of problems. I have, in other cases, executed a stored procedure asynchronously (thanks to a tip from this group) thru ADO. I'm wondering if ASP provides some way of executing a...
18
19487
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 executed will return one record and i want to use this data in the calling stored procedure. Is this possible ? Thanks in advance
5
9558
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 when I put the value in directly, eg. call sproc_test('1234') gives me a SQL0469N error. I'm pretty sure I was able to do this once before by declaring a variable in the CLP before making the call; but I can't remember how.
2
5463
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
4
6725
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 DB Provider for SQL Server SQLState: 42000
1
6136
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 label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the database. I have created the stored procedures for the insert,update,delete. I have...
3
4210
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 trying to call the page with the correct querystrings. The stored procedure looks like it's properly called , as i tried misspelling the stored procedure in the "CmdSP.CommandText = "resultsSP" " line, and the error prompted no such stored...
6
7291
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 (confirmation) declared in page. Dim RsSp , SQLSp Set RsSp = Server.CreateObject("ADODB.Recordset") SQLSp = "Declare @confirm varchar(1)" SQLSp = SQLSp & "Exec SendMsg_proc "& "'" & UniCode &"' , '" & DintUserId &"' , '" & DintOrg_id &"' ,...
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10542
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.