none
Reading and updating at the same time RRS feed

  • Question

  • Hi

    SQL Server 2008 backend.

    I am reading records from a table using datareader where a date field is null. Once read I need to update the date field to designate that records have been read. f I do the two (reading and updating) in two steps it’s possible that by the time records have been read and are being updated, new records have been entered by other users and their date gets updated even though they have not been read.

    How can I achieve the two reading and updating the date in one step?

    Thanks

    Regards

    Wednesday, March 9, 2011 8:30 PM

Answers

  • Hi Yahya,

    Welcome!

    When you read one record, you can use DateTime.Now to get time and store the record's Id and The time, then use Updatecommand to update your record in database.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Y a h y a Tuesday, March 15, 2011 1:50 AM
    Thursday, March 10, 2011 2:19 AM
    Moderator

All replies

  • Hi Yahya,

    Welcome!

    When you read one record, you can use DateTime.Now to get time and store the record's Id and The time, then use Updatecommand to update your record in database.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Y a h y a Tuesday, March 15, 2011 1:50 AM
    Thursday, March 10, 2011 2:19 AM
    Moderator
  • Hi Yahya,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 
     
    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day!


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 15, 2011 1:28 AM
    Moderator