Imran Bashir

Imran Bashir

  • NA
  • 186
  • 13.7k

Return Value from Stored Procedure To asp .net

Jul 31 2016 2:34 AM
i have this store procedure and i want to make this that will return the value to asp .net application when it is true or false...when the Store procedure return true then in asp lblresult.text=" true"; if the then that return false then lblResult=" falase";
 
============================================
  1. ALTER proc [dbo].[sp_Stock_check]    
  2.      
  3. @sum int ,    
  4. @product_id int    
  5.      
  6. as    
  7. begin    
  8. SELECT product_id    
  9.      
  10. COUNT(stock_in) as Count_stockIn    
  11. COUNT(stock_out) as Count_stockOut    
  12. SUM(stock_in) as Sum_stockIn    
  13.      
  14. ,    
  15. SUM(stock_out)+ @sum AS Sum_StockOut,    
  16. CASE WHEN SUM(stock_in) >= (SUM(stock_out)+@SumTHEN 'true' ELSE 'false' END AS IsInGreater    
  17. From Stock    
  18.      
  19. Group By product_id    
  20. having product_id = @product_id    
  21.      
  22. end  

============== Here is the asp .net code ========================

  1.    
  2. db.con.Open();  
  3.    
  4. db.com = new SqlCommand("sp_Stock_check", db.con);  
  5. db.com.CommandType = CommandType.StoredProcedure;  
  6.    
  7.    
  8. db.com.Parameters.AddWithValue("@product_id",ddlProduct.SelectedValue);  
  9. db.com.Parameters.AddWithValue("@sum", txtQuantity.Text);  
  10.    
  11. try  
  12. {  
  13. res = db.com.ExecuteNonQuery();  
  14. lblResult2.Text = "Successfully data enter";  
  15. }  
  16. catch (Exception ex)  
  17. {  
  18. lblResult.Text = ex.Message;  
  19. }  
  20. finally  
  21. {  
  22.    
  23. db.con.Close();  

 
 

Answers (2)