0

This is my function:

create function fn_Inventory(@qty int, @item_ID int)  
returns int
as begin
    declare @result int

    set @result = (SELECT Quantity - @qty from Items where @item_ID = item_ID)
    return @result
end

And I want to execute this function from my asp.net code; how to do it?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
appleduardo
  • 59
  • 2
  • 10

1 Answers1

0
public int TotalCupom(int qty,int item_ID)
    { 
        int result;           
        SqlDataAdapter da2 = new SqlDataAdapter();
        if (conex1.State == ConnectionState.Closed)
        { conex1.Open();}
        SqlCommand Totalf = new SqlCommand("SELECT dbo.fn_Inventory(@qty,@item_ID)", qty,item_ID);
        SqlParameter _qty= new SqlParameter("@qty", SqlDbType.Int);
        SqlParameter _item_ID= new SqlParameter("@item_ID", SqlDbType.Int);
        _qty.Value = qty;
        _item_ID.Value = item_ID;
        result= Totalf.ExecuteScalar();


        return result;
    }
P John Raj
  • 537
  • 1
  • 4
  • 17