getting RETURN from sql server using ado.net

getting RETURN from sql server using ado.net

Post by RitzCod » Sun, 09 Feb 2003 02:30:55



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

 
 
 

getting RETURN from sql server using ado.net

Post by Bill » Sun, 09 Feb 2003 02:44:14


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


 
 
 

1. Retrieving data from Exchange 2000 server using ado/ado.net

I am trying to make an application on a client machine
that will retrieve Outlook Calendar data from a Exchange
2000 Server. I have looked at several ways to do this
(making a webservice on the exchange server, using exoledb
or webdav and so on).

The solution i've found most suitable and interesting, is
using MSDAIPP.DSO as a ADO connection provider to retrieve
information with http:// URL. However I have only seen how
to do this with ADO, not ADO.NET. It is a bit troublesome
to use ADO in .NET and i'm not that familiar with it
either.

Does anyone know if it is possible to use MSDAIPP.DSO in
conjunction with ADO.NET, or if there is some other way to
retrieve data with ADO.NET from Exchange 2000 server? If
so, how is this done?

All help appreciated!

Regards
Jan Johansen

2. Spurious "Connection busy with results of another hstmt" messages

3. Getting return value from Oracle Stored Procedure using ADO

4. email attachment to database

5. How to connect to remote SQL Server using ADO.NET

6. info. How to access or setup a database in my internet account.

7. How to connect to SQL Server using ADO.NET and C#

8. IDENTITY_INSERT

9. SQL Server does not exist or access denied when using ADO .NET

10. SQL Server Access using ADO.Net through Internet

11. Calling a stored procedure on SQL Server using ADO.NET

12. Using ADO.Net to connect to a SQL Server Database

13. Getting SQL server Identity field using ADO