Link to home
Start Free TrialLog in
Avatar of MikeMCSD
MikeMCSDFlag for United States of America

asked on

How to Return a success or fail code from a Stored Procedure?

I'm running a stored procedure from code and I want to know if it completed succesfully:

            string connectionString = ConfigurationManager.ConnectionStrings["NopSqlConnection"].ConnectionString;
            using (var conn = new SqlConnection(connectionString))  
            using (var command = new SqlCommand("Import_Update", conn) {CommandType = CommandType.StoredProcedure})
            {
                conn.Open(); command.ExecuteNonQuery();
                conn.Close();

               //  Return a success or fail code

            }


ALTER PROCEDURE  Import_Update
AS
BEGIN
      SET NOCOUNT ON;

                UPDATE  . . .
                ..........

--   Return a success or fail code
 
END



What is the best way to do this?  thanks


ASKER CERTIFIED SOLUTION
Avatar of Jacobfw
Jacobfw
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeMCSD

ASKER

thanks, but that's in VB and is not using the same syntax as I am.
SOLUTION
Avatar of Navneet Hegde
Navneet Hegde
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Like!

 string connectionString = ConfigurationManager.ConnectionStrings["NopSqlConnection"].ConnectionString;
            using (var conn = new SqlConnection(connectionString))   
            using (var command = new SqlCommand("Import_Update", conn) {CommandType = CommandType.StoredProcedure})
            {
                conn.Open(); 
                returnValue = cmd.ExecuteScalar();

                conn.Close();

               //  Return a success or fail code

            }

Open in new window

Make sure your Stored proceudre return vale
liek on Success - Select 'true'
on Failuer   - Select 'false'

Thanks!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks all