Retrieve return value of SQL User Defined Function?

  • Thread starter Thread starter Mark B
  • Start date Start date
M

Mark B

I have been able to retrieve the scalar value of a SQL Server Stored
Procedure as follows:

Shared Function fGetGroupPerformanceStatistic(ByVal strGroup As String) As
String

Dim sqlConnection1 As New SqlConnection("Data
Source=MARK\SQLEXPRESS;Initial Catalog=GroupSales;Integrated
Security=True;")
Dim cmd As New SqlCommand

cmd.CommandText = "ufWebStatsAverageSalesGroup"
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Connection = sqlConnection1
sqlConnection1.Open()
cmd.Parameters.Add(New SqlParameter("@EnterGroup", strGroup))
fGetGroupPerformanceStatistic = cmd.ExecuteScalar()
sqlConnection1.Close()

End Function


Now I want to retrieve the value from an SQL Server User Defined Function
udf.GetTopSalesFigure(@EnterGroup nvarchar(50))

How would I do that in VB code similar to the code above?

Also, can I do it by just dragging an SQLDataSource control onto the aspx
page and referencing that?
 
I have been able to retrieve the scalar value of a SQL Server Stored
Procedure as follows:

Shared Function fGetGroupPerformanceStatistic(ByVal strGroup As String) As
String

Dim sqlConnection1 As New SqlConnection("Data
Source=MARK\SQLEXPRESS;Initial Catalog=GroupSales;Integrated
Security=True;")
Dim cmd As New SqlCommand

cmd.CommandText = "ufWebStatsAverageSalesGroup"
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Connection = sqlConnection1
sqlConnection1.Open()
cmd.Parameters.Add(New SqlParameter("@EnterGroup", strGroup))
fGetGroupPerformanceStatistic = cmd.ExecuteScalar()
sqlConnection1.Close()

End Function

Now I want to retrieve the value from an SQL Server User Defined Function
udf.GetTopSalesFigure(@EnterGroup nvarchar(50))

How would I do that in VB code similar to the code above?

Also, can I do it by just dragging an SQLDataSource control onto the aspx
page and referencing that?

Hi

follow this thread...

http://forums.devx.com/showthread.php?t=146418

call function in store procedure call the store procedure from asp.net

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 
if you have a function GetTopSalesFigure(<some paremeters>), then in
your stored proc

create stored procedure fGetGroupPerformanceStatistic
(
....your parameters...
)
as
select dbo. GetTopSalesFigure(<some paremeters>) as
test_function_result



.... more articles at http://www.siccolo.com/articles.asp
 
Back
Top