.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> .Net Framework >> Post New Resource Bookmark and Share   

 Subscribe to Articles

To check whether a particular row exists by using a stored procedure return value

Posted By:Shashi Ray       Posted Date: November 30, 2009    Points: 25    Category: .Net Framework    URL: http://www.dotnetspark.com  
 

 

To check whether a particular row exists by using a stored procedure return value

  1. Establish a SqlCommand object to call the stored procedure.
  2. Set up an input parameter that contains the primary key value of the row to be accessed.
  3. Set up the single return value parameter. Add a SqlParameter object to the SqlCommand's Parameters collection, and set its direction to ParameterDirection.ReturnValue.
  4. Open the connection.
  5. Call the ExecuteNonQuery method of the SqlCommand object.
  6. Close the connection.
  7. Retrieve the return value by using the Value property of the return value SqlParameter.

The preceding code uses the following stored procedure.

CREATE PROCEDURE CheckProductSP 
@ProductID int
AS
IF EXISTS( SELECT ProductID
           FROM Products
           WHERE ProductID = @ProductID )
  return 1
ELSE
  return 0
GO

 

Shashi Ray

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend