Friday, March 30, 2012

restrict deletion

What would be the best practice to prevent users who didn't create a record in sql from deleting? When a record is created I have the username who created the record in one of the fields. I was thinking maybe a query?

Thank you in advance.

I have used same practice.|||Thank you Javier.|||

Hi fpena,

You can just compare the username again to the current user to see if he is the owner of this record. If yes, delete it. All this can be done in a single stored procedure.

HTH. If this does not answer you question, please feel free to mark it as Not Answered and post your reply. Thanks!

|||could you point me on the right direction? Thank you.|||

Hi fpena,

You can use a single sentence to achieve that. Assume that there is a field in the table named RecordOwner, and your stored procedure passes in a parameter named @.Deleter. You can use

DELETE FROM Table1 WHERERowID=@.RowID ANDRecordOwner=@.Deleter

You can check the AffectedRows in your code. If it is 0, it means that the row does not exist or the deleter is not the owner, so that he cannot delete it.

|||i'm not sure i can accomplish what i'm looking for with that. i have a gridview visible to everyone all records visible no matter what userID owns the record what i'm trying to do is prevent a user who doesn't own a record from deleting when trying to delete. hope my question is clear enough. Thank you.|||

Hi fpena,

I'm sure that this will do what you need. You just need to modify the delete command you're currently using to check the ownership info.

If you have any questions on how to do this, please feel free to reply to my post.

|||

how is it done?

No comments:

Post a Comment