Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In the Google excel,if 2 users are working with a cell at the same time,they will know each other is editing it.
My question is how to implement this effect in the environment(C#,SQL Server),can the database sent a message to users about who is editing the data, or some else solution?
Posted

One way of doing this is by putting an additional flag column on your table. This way, a user who edits a record will be able to lock it by setting true to that flag. And when another user attempts to edit that record, the application checks the flag if its currently being edited or not. The record will be unlocked when the user who locked it decides to save/discard his changes.
 
Share this answer
 
Comments
eric881027 11-Jul-11 22:03pm    
Yeah,I thought about that,by this way the app have to read the data all the time.I want the database takes the initiative to send a message to the app.
walterhevedeich 11-Jul-11 22:26pm    
The app will only read the flag column if a user wishes to edit a record, not all the time. Since this is just a single column, I don't think there will be a problem on the performance, if that's what you're concerned about. Think about it this way, you want the database to have the initiative to send you a message that the record is currently being edited, but you're database has to have a basis on whether the record is in edit mode or not. In this case, locking the record is a good way to tell the database that the record is in edit mode.
eric881027 12-Jul-11 1:16am    
Ok,thanks,do you think the Service Broker can handle this effect?
As walter said, the most common way to do this, is to have one user LOCK the file, with a marker in the DB. Code Project does this too, when one person edits question on this forum, it tells you who has locked it, and no-one else can edit. To support two people editing at once, you would need a merging functionality that will make sure the two different sets of edits are both preserved. Then the question becomes, how do you reconcile if two people edited the same part of the document ? It's far easier to just let one person edit at a time.
 
Share this answer
 
Comments
eric881027 11-Jul-11 22:16pm    
Thanks,locking the database is also a good solution,my point is how the database tell users who is editing the data,or the app has to read the database all the time to get this information.
Christian Graus 11-Jul-11 22:18pm    
The database cannot send any sort of message. It's a database. If you set a lock on a file to start editing, then you need to talk to the DB to do that. When you do that, you'd first check if it's already locked. If it is, instead of showing the 'edit' page, you'd show a 'this file has been locked' page.
eric881027 12-Jul-11 1:16am    
Ok,thanks,do you think the Service Broker can handle this effect?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900