Groups | Blog | Home
all groups > sql server clients > may 2004 >

sql server clients : out parameter


Andrew J. Kelly
5/22/2004 12:12:43 PM
I don't think this has a C# example but it does explain OutPut parameters:
http://www.support.microsoft.com/?id=262499

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

Ran Y
5/22/2004 3:11:04 PM
hello all,

i am trying to get a returned value from a SP using an out parameter.

my code is in C# and i need some help (pls).
be greatfull if you send an example of the SP and the C# code that execute
it and collect the returning parameter value.

thanks a lot, Ran.

Erland Sommarskog
5/23/2004 10:05:52 PM
[posted and mailed, please reply in news]

Ran Y (ranyc@012.net.il) writes:
[quoted text, click to view]

You did not specify which .Net Data Provider you are using, so I am
assuming SqlClient. Furthermore, the code I have around is VB.Net,
so you will need to transliterate in to C# on your own:

Dim p As SqlParameter = New SqlParameter
p.ParameterName = "@outparam"
p.DbType = SqlDbType.Int ' For instance.
p.Direction = ParameterDirection.InputOutput
p.Value = DBNull.Value
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery ' Or .Fill or an .ExecuteReader loop

The value of @outparam is now in p.Value.

There are a couple of variations on how you can create the
parameter, see the online documentation for this.

--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
AddThis Social Bookmark Button