472,351 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 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 50236
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...
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...
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...
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...
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...
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....
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...
2
by: jed | last post by:
I have created this example in sqlexpress ALTER PROCEDURE . @annualtax FLOAT AS BEGIN SELECT begin1,end1,deductedamount,pecentageextra...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.