473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 [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...

Jan 17 '06 #1
4 50375
Welcome Mr Not So Know it All to this newsgroup
Try looking at this article at :-
http://aspnet.4guysfromrolla.com/articles/062905-1.aspx
It should help you
Patrick

"Mr Not So Know It All" <dj****************@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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...

Jan 17 '06 #2
thanks patrick
i read the article and it was helpful. it didn't mention how to return
multiple values with an output parameter. for example, say my select
statement returned four employee id numbers, how would i use an output
variable to return them? or maybe an output variable can only return
one value (as in the example from the article, the output parameter
returns one aggregate function result).

i found this in microsoft's web site

ExecuteReader Executes commands that return rows. For increased
performance, ExecuteReader invokes commands using the Transact-SQL
sp_executesql system stored procedure. As a result, ExecuteReader may
not have the desired effect if used to execute commands such as
Transact-SQL SET statements.

http://msdn.microsoft.com/library/de...classtopic.asp

maybe that is my problem. thanks again patrick for the help and further
assistance.

Jan 17 '06 #3
sql output parameters (like input) are scalar, so you can not return
mutilple values, short of concating the values into a string. you want to
return a result set containg rows.

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

this will return multiple values. in .net you can access them with a
datareader or datatable.

-- bruce (sqlwork.com)

"Mr Not So Know It All" <dj****************@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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...

Jan 17 '06 #4
thx bruce. that makes a lot of sense considering my results. i
appreciate the time and effort.

Jan 17 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steven | last post by:
I'm calling a stored procedure which has an output parameter of type int. Once the stored procedure is executed, I want to check the value of the parameter in case it is null. However, when the a...
2
by: Dino L. | last post by:
How can I run stored procedure (MSSQL) ?
5
by: MS | last post by:
Here's my simple stored procedure: ALTER PROCEDURE GetMemberIDByEmail @Email EmailAddress, @ID int OUTPUT AS SELECT @ID = ID FROM tbl_Member WHERE Email=@Email RETURN
2
by: Eli | last post by:
Hi all We currently have a strange problem with calling a Stored Procedure (SQL Database) in our C# Project. The only error I get is "System error" which says a lot :) Background: We have...
0
by: Amber | last post by:
Stored procedures are faster and more efficient than in-line SQL statements. In this article we will look at two SQL Server stored procedures; one using an input parameter and one not, and see how...
3
by: Bilbo | last post by:
I have a a headscratcher here: I have a form that when submitted should do 2 things when a user enters data and then clicks the Add button. Here goes: 1. Call a stored procedure called...
10
by: J. S. EDV | last post by:
Hello, I have got a little problem with stored procedures and C#. I have got a stored procedure which should only insert something in a table. For example: ALTER PROCEDURE DBO.PROC1 AS...
7
by: ashtek | last post by:
Hi, I have a generic function that executes a stored procedure & returns a data table. Code: === public static DataTable ExecuteStoredProcedure(string strProc,SqlParameter paramArray) {...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra FROM tax
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...

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.