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 8127911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:42:05+00:00 2026-06-06T07:42:05+00:00

I have an app that runs a stored procedure in SQL Server, checking the

  • 0

I have an app that runs a stored procedure in SQL Server, checking the difference of times between one row in a table and getdate()

I call this stored procedure from c#, and use a @returnValue to do some things

This is the method

public static bool Check(string CheckStored)
{
    using (DbCommand command = DatabaseDA.DefaultDb.GetStoredProcCommand(CheckStored))
    {
        DatabaseDA.DefaultDb.AddParameter(command, "ReturnValue", DbType.Boolean, ParameterDirection.ReturnValue, "", DataRowVersion.Current, 0);
        DatabaseDA.DefaultDb.ExecuteNonQuery(command);

        return Convert.ToBoolean(command.Parameters["@ReturnValue"].Value);
    }
}

and this is the call

bool notifNeeded = NotificationsDA.Check("CheckLastEnvioListadoComprobanteEjercicio");

then in SQL Server I have:

ALTER Procedure [dbo].[CheckLastEnvioListadoComprobanteEjercicio]
as
Begin

declare @UltimoEnvio datetime
declare @ReturnValue bit 
select @UltimoEnvio = LastDate from EnvioListadoEjercicioComprobantes 

Select @returnValue = CASE 
                         WHEN DATEDIFF(hour, @UltimoEnvio, getdate()) >= 1 THEN 1
                         ELSE 0 
                      END   
from rep_inboxRequest

if (@ReturnValue = 1)
    update EnvioListadoEjercicioComprobantes set LastDate = getdate()

return @ReturnValue
END 

in EnvioListadoEjercicioComprobantes I have a row with the lastDate of one action (ej sending mail).

Right now, I have only one row, with 2012-06-18 06:40:02.210 value. I compare this date with the actual date, and return a bit if the difference is more than an hour.

Right now, in Argentina, its about 2012-06-18 11:26

If I execute getdate() in SQL Server, I get 2012-06-18 11:30:44.027

If I run my entire stored procedure in SQL Server and print @ReturnValue, I get 1 and the row is updated-

But when I call my stored from C#, I always get 0, and of course, the row didn’t update.

What am I doing wrong ?

  • 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-06T07:42:06+00:00Added an answer on June 6, 2026 at 7:42 am

    Why are you doing all that work (declare, select, update conditionally) when you can just perform a conditional update?

    ALTER PROCEDURE [dbo].[CheckLastEnvioListadoComprobanteEjercicio]
    AS
    BEGIN
      SET NOCOUNT ON;
    
      UPDATE dbo.EnvioListadoEjercicioComprobantes 
        SET LastDate = GETDATE()
        WHERE LastDate <= DATEADD(HOUR, -1, GETDATE());
    
      IF @@ROWCOUNT > 0
        RETURN 1;
      ELSE
        RETURN 0;
    END
    GO
    

    Anyway I don’t think that’s the way you deal with a return value. Try something like this (this is pseudo-code):

    DatabaseDA.DefaultDb.ExecuteNonQuery(command);
    var returnVal = command.Parameters.Add("@ReturnValue", SqlDbType.Int);
    returnVal.Direction = ParameterDirection.ReturnValue; // this is important
    DatabaseDA.DefaultDb.ExecuteNonQuery(command);
    return Convert.ToBoolean(returnVal.Value);
    

    Otherwise I suggest you stop using a return value for this, if you want the return parameter to be bit coming out of SQL Server, you can use an output parameter.

    ALTER PROCEDURE [dbo].[CheckLastEnvioListadoComprobanteEjercicio]
      @ReturnVal BIT = 0 OUTPUT
    AS
    BEGIN
      SET NOCOUNT ON;
    
      UPDATE dbo.EnvioListadoEjercicioComprobantes 
        SET LastDate = GETDATE()
        WHERE LastDate <= DATEADD(HOUR, -1, GETDATE());
    
      SELECT @ReturnVal = @@ROWCOUNT;
    END
    GO
    

    Now in your C# code (again, this is pseudo-code, I don’t know that it will magically compile in your app if you copy and paste, but it should give you the idea):

    SqlParameter rv = new SqlParameter("@ReturnVal", SqlDbType.Boolean);
    rv.Direction=ParameterDirection.Output;
    command.Parameters.Add(rv);
    command.ExecuteNonQuery();
    return Convert.ToBoolean(rv.Value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple of stored procedures on SQL Server 2005 that I've noticed
Using SQL Server 2008 I created a Stored Procedure called MyStoreProc and it runs
I have an app that runs a webview as a service so the audio
i have an app that runs perfectly on android 1.6+, but admob ads are
I have a web app that runs fine in Visual web developer. But when
I have a Cordova app that runs the jQuery mobile framework and loads pages
I have a windows app that runs correctly in my PC that is 96DPI
I have a web app that runs perfectly on Apache Tomcat. However, when I
I have a web database app that runs in IE7+ (customer requirement) It is
I have written a C# app that runs constantly in a loop and several

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.