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

  • Home
  • SEARCH
  • 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 628599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:39:15+00:00 2026-05-13T19:39:15+00:00

I am currently working on a C# windows form with linq-to-sql that selects a

  • 0

I am currently working on a C# windows form with linq-to-sql that selects a row from a SQL table and then allows the user to edit the fields in that row. This form will be used by multiple users at a time and I would like to have it so when someone has selected a row and is currently entering data in the form (with which the row will be updated once the user hits a button on the form) no one else may select that row. Once the user hits the button to execute an update query the updated row should be selectable again. Essentially the process is:

user selects row–>row becomes unselectable by other users–>user modifies row fields values–>user submits and row updates–>row becomes selectable again.

Is there some sort of existing functionality I can use to accomplish this or will I need to create a table that tracks which rows are unselectable and have the application query that table before selecting rows (ie query table to see if row is unavailable, if not insert rowid user is editing, then delete row after user has submitted changes)?

  • 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-05-13T19:39:16+00:00Added an answer on May 13, 2026 at 7:39 pm

    What you are trying to do is enforce non-optimistic concurrency on the resources you are accessing (in this case, database rows).

    Generally, the data models in .NET only support optimistic concurrency (if you are supporting concurrency at all, that is), and most database programming that you see nowadays follows the same trend.

    That being said, you should probably look at an optimistic concurrency model, where you have a timestamp of some sort (whether it be a binary value or a date, something that changes with each update to the record) which is compared when you want to perform the update operation.

    If the id and the timestamp match, the operation succeeds, otherwise, it informs the user someone else has updated the record and should reload the data and try to update the record again.

    It should be noted that this pattern scales much, much better than any non-optimistic patterns.

    That being said, if you truly want a non-optimistic pattern, you have to fake it.

    As mentioned above, the .NET data provider models do not support non-optimistic concurrency. When a user begins the operation, it would check a field (“locked” or something like that) to see if the record is currently locked. If it is locked, then you don’t allow the user to open the form to modify the data. If it is NOT locked, then you allow the user to open the form and modify the data.

    There are two important things that you have to do here. The first is to set the “locked” field to true, to indicate that you have a lock.

    The second is to make sure you are operating in a transaction when comparing the value and updating the locked field. If you don’t, then the possibility of two clients updating the field at the same time exist, which you don’t want.

    The best way to encapsulate this is to have a stored procedure which takes the id of the record you want to lock.

    It then performs an update, like so:

    --- Update the table.
    update <table> set locked = 1 where id = @id and locked = 0
    
    --- Return the rowcount.
    return @@rowcount
    

    It should be noted that the check on the “locked” field is very important, as it allows the @@rowcount value to be either 0 or non-zero (depending on whether or not your ids are unique) which you can evaluate to false in the zero case and true in the non-zero case in your application code.

    Then, in your application code, you complete the transaction, and if the value is true, you open the form and allow the user to edit, otherwise, you inform them they have to wait.

    When the user is done saving the record, they set the “locked” bit back to zero, again, in a transaction with the other save operations.

    The one glaring drawback to this is the fact that if your application crashes after the user has locked the record, it will never become unlocked, and you will have to manually go and remove the “locked” bit.

    With transactions and optimistic concurrency, you don’t have to worry about any of this, so I would again, strongly urge you to not use the non-optimistic concurrency model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 319k
  • Answers 319k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This can happen, as Raymond Chen writes: Consider what would… May 14, 2026 at 12:13 am
  • Editorial Team
    Editorial Team added an answer You could use it's name to find it. F.e. public… May 14, 2026 at 12:13 am
  • Editorial Team
    Editorial Team added an answer No, it only displays extra backslashes so that the string… May 14, 2026 at 12:13 am

Related Questions

I'm currently writing myself a little C# back up program. I'm using a standard
Currently my workflow with Emacs when I am coding in C or C++ involves
I been going through this tutorial and it looks really good. So I went
I am trying to open an InfoPath 2007 file programmatically from a Windows service,
My company has developed a long standing product using MFC in Visual C++ as

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.