You need to create a Command object (SqlCommand) and create a Parameters
collection. The RETURN value is passed back as the first parameter. I'm not
going to write a C# example for you (I'm not into that kind of abuse), but
this VB.NET example should help. It's featured in a new article to be
(eventually) published in MSDN magazine.
Try
Dim bolEOF As Boolean
cn = New SqlConnection("server=demoserver;database=biblio;integrated
security=sspi")
Dim cmd As New SqlCommand("OutputTitleByISBNandType", cn)
cmd.CommandType = CommandType.StoredProcedure
With cmd.Parameters
ParameterDirection.Output
ParameterDirection.ReturnValue
cn.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
' process rowset(s)
bolEOF = dr.Read
Do
Do While bolEOF = True
' Process rows
bolEOF = dr.Read()
Loop
Loop While dr.NextResult = True
cmd.Cancel()
dr.Close()
End With
Catch ex As Exception
MsgBox(ex.ToString)
Finally
cn.Close()
End Try
End Sub
hth
--
____________________________________
Bill Vaughn
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
> Hi. Can someone tell me how to get the return value from a stored
> proc. using ado.net? I have the following c# code:
> int test = (int)(com.ExecuteScalar());
> My stored proc is:
> CREATE PROCEDURE xxxx
> AS
> -- add rec
> GO
> I know that i could use a select and get the id back that way but I
> cannot change the procedure so I need to be able to get the result
> back from the RETURN. Thanks very much for any help.
> Ritz