Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7868159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:54:42+00:00 2026-06-03T00:54:42+00:00

I have an sql query that uses transactions, and it uses return to indicate

  • 0

I have an sql query that uses transactions, and it uses return to indicate failure or success, like so:

BEGIN

    DECLARE @intErrorCode INT;
    DECLARE @emailAutoIncrement INT;

    BEGIN TRAN


    INSERT  INTO Accounts ( blabla, blabla2 )
    VALUES  ( somevalue, somevalue2 )

    Select @intErrorCode = @@ERROR
    if (@intErrorCode <> 0) GOTO PROBLEM

    COMMIT TRAN
    RETURN 1


    PROBLEM:
    if (@intErrorCode <> 0) Begin
    Rollback Tran
    RETURN 0
    END

END

From code, I used sqlCommand.ExecuteScalar() thinking that this will give me either 1 or 0, but this always returns false. Also, another problem I have is that when an exception happens in the sql and the program is meant to return 0, it actually returns the exception.

So the RETURN 0 is useless because it is always overridden by the exception?

To add some more information, the sql query is a stored procedure and it is called like so:

                myCommand.CommandText = "createAccount";
                myCommand.CommandType = CommandType.StoredProcedure;
                //Add parameters here
                using (myReader)
                {
                    var test = myCommand.ExecuteScalar();
                }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:54:44+00:00Added an answer on June 3, 2026 at 12:54 am

    try SELECT rather than RETURN

    BEGIN
    
        DECLARE @intErrorCode INT;
        DECLARE @emailAutoIncrement INT;
    
        BEGIN TRAN
    
    
        INSERT  INTO Accounts ( blabla, blabla2 )
        VALUES  ( somevalue, somevalue2 )
    
        SET @intErrorCode = @@ERROR
        if (@intErrorCode <> 0) GOTO PROBLEM
    
        COMMIT TRAN
        SELECT 1
    
    
        PROBLEM:
        if (@intErrorCode <> 0) Begin
        Rollback Tran
        SELECT 0
        END
    
    END
    

    I also changed

    SELECT @intErrorCode = @@ERROR
    

    to

    SET @intErrorCode = @@ERROR
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an SQL SELECT query that also uses a GROUP BY , I
I have an SQL query that uses GROUP_CONCAT to get all people attached to
If I have a sql query that uses 'distinct' (in oracle), would it be
I have a controller action that uses a sql query: $tag = $this->params['tag']; $this->set('projects',
I have a SQL query that I'm trying to debug. It works fine for
I have an SQL query that returns all companies records ignore the ones with
I have a SQL query that I'm trying to write, but I'm not quite
I currently have a SQL query that returns a number of fields. I need
I need to be able to have an SQL query that searches my database
i have a huge sql query that is attached to the rowsource of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.