keyongtech


  keyongtech > dotnet.framework.* > dotnet.framework.adonet > 01/2006

 #1  
01-17-06, 02:32 AM
Mr Not So Know It All
im new to SQL Server and ASP.Net. Here's my problem. I have this SQL
Server stored procedure with an input parameter and output parameter

CREATE PROCEDURE [safety].[_getRCList]
@in_rc varchar(8)
@out_eList varchar(7) output
AS
select @out_eList = ecuid from _organization where rccode = @in_rc
GO

im trying to get the values from the select statement. for example, if
@in_rc is a value that has mutiple ecuids, i would like to have the
@out_eList equal to those values.

here is the asp.net code im using to get the output parameters from the
SQL Server stored procedure.

sqlComm = new sqlCommand("_getRCList",conn)
sqlComm.commandtype = commandtype.storedprocedure

'add input parameter
sqlComm.parameters.add("@in_mcuid","lxkqchy")
'add output parameter
sqlParameter = sqlComm.parameters.add("@out_eList",sqlDBtype.varc har)
sqlParameter.size = 20
sqlParameter.direction = parameterdirection.output
'execute command
dtrEList = sqlComm.executeReader(CommandBehavior.CloseConnect ion)
response.Write("<br> rows : " & dtrEList.hasrows & "<br>")
while dtrEList.read()
response.Write("<li>")
response.Write("CUID " & dtrEList(0) & "<br>")
end while
dtrEList.close()

is this the right way to get values from a stored procedure? please
help...
 #2  
01-18-06, 09:11 AM
Milosz Skalecki
Hi,

You can return result sets from stored procedure. You can assign one value
to the output parameter not a set of values as you're doing it now. Please
also note that when you use DataReader, value of the out parameter becomes
available after you closing it. Modify stored proc as follows:

CREATE PROCEDURE [safety].[_getRCList]
@in_rc varchar(8)
AS
select ecuid from _organization where rccode = @in_rc
GO

Then process the result set:
sqlComm = new sqlCommand("_getRCList",conn)
sqlComm.commandtype = commandtype.storedprocedure

'add input parameter
sqlComm.parameters.add("@in_rc","lxkqchy")
'execute command
dtrEList = sqlComm.executeReader(CommandBehavior.CloseConnect ion)
response.Write("<br> rows : " & dtrEList.hasrows & "<br>")
while dtrEList.read()
response.Write("<li>")
response.Write("CUID " & dtrEList(0) & "<br>")
end while
dtrEList.close()

If you want to use output parameters here's an example

CREATE PROCEDURE [safety].[_getRCList]
@in_rc varchar(8),
@Count int OUTPUT -- it's just an example :)
@
AS
set @Count = (SELECT Count(IdColumn) FROM _organization where rccode = @in_rc
select ecuid from _organization where rccode = @in_rc
GO

and vb.net code

sqlComm = new sqlCommand("_getRCList",conn)
sqlComm.commandtype = commandtype.storedprocedure

'add input parameter
sqlComm.parameters.add@in_rc","lxkqchy")
'add output parameter
sqlParameter = sqlComm.parameters.add("@Count",sqlDBtype.Int)
sqlParameter.direction = parameterdirection.output
'execute command
dtrEList = sqlComm.executeReader(CommandBehavior.CloseConnect ion)
response.Write("<br> rows : " & dtrEList.hasrows & "<br>")
while dtrEList.read()
response.Write("<li>")
response.Write("CUID " & dtrEList(0) & "<br>")
end while
dtrEList.close()
' obtain output value after reader closing the reader
dim OutputValue as Integer = Convert.ToInt32(dtrEList("@Count"))


Hope my example is not so messy as it looks like :]
Similar Threads
SQL Server stored procedure output parameters.

Hello. I'm having difficulty getting the value of output parameters from stored procedures on a SQL server. I understand that this just doesn't work with odbc so I've tried...

Stored Procedure with Output Parameters

Hi all I'm tryng to use MSDAORA access in a Oracle 9 database. I have a stored procedure named TEST with this Sign : PROCEDURE TEST ( PC_01 IN VARCHAR2 ,PC_02...

SQL Server Stored Procedure with Output Parameter and ASP.NET SQLCommand

im new to SQL Server and ASP.Net. Here's my problem. I have this SQL Server stored procedure with an input parameter and output parameter CREATE PROCEDURE...

Passing output parameters to SQL Server stored procedures through an SqlCommand object's Parameters collection

Hi, I'm currently working writing a Windows service in C# which needs, among other things, to interface with Microsoft Great Plains 8.0, specifically to add General Ledger...

Stored Procedure Output Parameters

I have a Stored procedure in SQL, that works, when tested in SQL, with one input & several output parameters, as follows: CREATE PROCEDURE myProcedure @MyID int , @First...


All times are GMT. The time now is 11:19 PM. | Privacy Policy