Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

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

 
Thread Tools Search this Thread
Old 01-17-2006, 02:34 AM   #1
Default 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(
@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...



Mr Not So Know It All
  Reply With Quote
Old 01-17-2006, 03:50 AM   #2
Patrick.O.Ige
 
Posts: n/a
Default Re: SQL Server Stored Procedure with Output Parameter and ASP.NET SQLCommand
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" <> wrote in message
news: 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(
> @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...
>





Patrick.O.Ige
  Reply With Quote
Old 01-17-2006, 09:44 AM   #3
Mr Not So Know It All
 
Posts: n/a
Default Re: SQL Server Stored Procedure with Output Parameter and ASP.NET SQLCommand
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.



Mr Not So Know It All
  Reply With Quote
Old 01-17-2006, 06:09 PM   #4
Bruce Barker
 
Posts: n/a
Default Re: SQL Server Stored Procedure with Output Parameter and ASP.NET SQLCommand
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(
@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" <> wrote in message
news: 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(
> @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...
>





Bruce Barker
  Reply With Quote
Old 01-17-2006, 07:24 PM   #5
Mr Not So Know It All
 
Posts: n/a
Default Re: SQL Server Stored Procedure with Output Parameter and ASP.NET SQLCommand
thx bruce. that makes a lot of sense considering my results. i
appreciate the time and effort.



Mr Not So Know It All
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Demo projects in Asp.net with C# and sql server?? CouponAlbum General Help Related Topics 0 05-01-2009 01:17 PM
help me for SQL server 2000 and ASP.NET rishabhsethi General Help Related Topics 0 12-27-2007 10:19 AM
Error Accessing SQL Server from ASP.Net srvking Software 3 12-18-2007 09:18 PM
populating data from sql server to pdf using asp.net gijichacko Software 0 08-10-2007 12:31 PM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46