locked
how to know whether record is updated or not RRS feed

  • Question

  • User2031860760 posted

    hello everyone i am describing my problem that i am sending a autogenerated e-mail....in which i am sending a link to activate an account....in which i have to apply an update commant....which is given below.

    Now i am confused with that how to know whether data has been updated or not in table....there is an property recordsAffected but if a user already activated his account.

    In that case RecorrdAffected will be zero so how i could i come to know....whether the account has been activated or he is trying to re-activate it...or he trying to activate a wrong account....

    command.CommandText = "update xxxx set ACT_STAT = 1 where P_ID = '" + name + "'";

    Wednesday, May 30, 2012 3:20 AM

Answers

  • User1320101480 posted

    When you do an update, it'd immediately return rows updated: It Return Number of Records Affected

    In case you are sending email first and then doing an update and you have this concern saying, before your update user may read his mail and activate and from there another update command may run before your's then there's a problem with your model.

    User being activated and mail being sent are two different things and should be stored in two diff places(columns)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 30, 2012 3:28 AM
  • User-661350001 posted

    create a SP in that 

    1) first check if the account is already activated then retun 1000

    2) if not activated then run the update statement and return 100

    3) use try and catch if any exception then return -1

    and so on

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 30, 2012 3:40 AM
  • User960609757 posted

    Hi,

    @@ROWCOUNT will give you the number of records affected by a SQL Statement.

    The following example executes an UPDATE statement and uses @@ROWCOUNT to detect if any rows were changed

    UPDATE HumanResources.Employee  SET JobTitle = N'Executive' WHERE NationalIDNumber = 123456789
    IF @@ROWCOUNT = 0
    PRINT 'Warning: No rows were updated';


    using Stored Procedure,

    Register an out parameter for the stored procedure, and set the value based on @@ROWCOUNT if using SQL Server. Use SQL%ROWCOUNT if you are using Oracle.

    Mind that if you have multiple INSERT/UPDATE/DELETEs, you'll need a variable to store the result from @@ROWCOUNT for each operation.



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 30, 2012 3:40 AM

All replies

  • User1320101480 posted

    When you do an update, it'd immediately return rows updated: It Return Number of Records Affected

    In case you are sending email first and then doing an update and you have this concern saying, before your update user may read his mail and activate and from there another update command may run before your's then there's a problem with your model.

    User being activated and mail being sent are two different things and should be stored in two diff places(columns)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 30, 2012 3:28 AM
  • User-661350001 posted

    create a SP in that 

    1) first check if the account is already activated then retun 1000

    2) if not activated then run the update statement and return 100

    3) use try and catch if any exception then return -1

    and so on

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 30, 2012 3:40 AM
  • User960609757 posted

    Hi,

    @@ROWCOUNT will give you the number of records affected by a SQL Statement.

    The following example executes an UPDATE statement and uses @@ROWCOUNT to detect if any rows were changed

    UPDATE HumanResources.Employee  SET JobTitle = N'Executive' WHERE NationalIDNumber = 123456789
    IF @@ROWCOUNT = 0
    PRINT 'Warning: No rows were updated';


    using Stored Procedure,

    Register an out parameter for the stored procedure, and set the value based on @@ROWCOUNT if using SQL Server. Use SQL%ROWCOUNT if you are using Oracle.

    Mind that if you have multiple INSERT/UPDATE/DELETEs, you'll need a variable to store the result from @@ROWCOUNT for each operation.



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 30, 2012 3:40 AM