Call function

  • Thread starter Thread starter BGO.UGent
  • Start date Start date
B

BGO.UGent

If have created this function for SQL Server 2005 Express, and want to
call it from C#.

Function is called in SQL as :
SELECT pkstock, fkStock, dbo.fGetStockPositionByName('0.5') from
tblStock where pkStock = '6'

compleet sql script included.

How must I build this code for passing the variables en retrieving the data.
Is this simular to a Stored Proc?
 
¤ If have created this function for SQL Server 2005 Express, and want to
¤ call it from C#.
¤
¤ Function is called in SQL as :
¤ SELECT pkstock, fkStock, dbo.fGetStockPositionByName('0.5') from
¤ tblStock where pkStock = '6'
¤
¤ compleet sql script included.
¤
¤ How must I build this code for passing the variables en retrieving the data.
¤ Is this simular to a Stored Proc?

Yes, but I would recommend wrapping the above SQL in a stored procedure and then calling the sp from
your code:

http://www.codeguru.com/columns/VB/article.php/c8671/


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Thanks Paul for the link for the .net Code.

I tried to wrap a SP around the function and comes to something like this:
Create Procedure spGetStockPositionByName
(
@StockName as varchar(5)
,@StockID as int
)
as

SELECT
pkstock
,fkStock
,dbo.fGetStockPositionByName(@StockName)
FROM tblStock
WHERE pkStock = @StockID

When i call the function [Select pkstock, fkStock,
dbo.fGetStockPositionByName('0.5') from tblStock where pkStock = '6']
I get the following result
6 3 INW/S12/0.5

when I call the SP [Exec spGetStockPositionByName @StockName =
'0.5',@StockID = '6']
I get the same result
6 3 INW/S12/0.5

So now I translate you VB code to C# and I can start working !!!

Code is added as extra value for people go might need the code.


Bart Goossens
 
Back
Top