Prevent Record Editing

Bob721

Member
Joined
Oct 15, 2007
Messages
6
Programming Experience
Beginner
I'm using VB 2005 with a SQL Server 2000. I have an application that is working well but it currently allows users to edit existing records (which we don’t want). In MS Access you could just set the "Allow Edits" property to false, but that’s not an option in VB with SQL. Does anyone know how I can lock down each record after it is added so it cannot be modified?
 
Added to what? There's nothing inherent in a database that will prevent that. It's all up to the UI. You've told us nothing about your UI so we can't tell you how to make it do what you want.
 
Sorry, I'll try to provide more detail. Basically the application is used to input answers to a survey. The windows form is just a bunch of checkboxes and text fields that the users enter based on the hard copy of the surveys that come in. What I'm looking for it to do is allow users to enter in the survey information and then move to the next survey, but not allow anyone to edit a survey after it was initially entered and saved.

My UI is very basic. I'm still learning how to program so I haven’t added much manual coding yet. Visual Basic 2005 automatically added in the dataset, binding source, table adapter, and binding navigator. All I've done is link each object to the correct field in the database.

I've attached a screenshot of my UI (not sure if that helps illustrate what I'm saying above, but it couldn’t hurt). Thanks for your help!
 

Attachments

  • screenshot.JPG
    screenshot.JPG
    246.9 KB · Views: 48
Another random thought. Could you set up a SQL user that only has INSERT and SELECT rights, and no UPDATE rights, and connect to the database with this?
 
why not just do a simple thing and have 2 forms.

one to add data, one to browse.

on the add form, remove the navigation buttons.

on the browse forms, remove the add, delete and save buttons.


alternatively, use some sort of validation on the AddNew command, with a form level parameter (in example blnNewUpdate as Boolean)

VB.NET:
Private Sub AddNew (.......)

me.surverybindingsource.addnew()
blnNewUpdate = True

End Sub

Private Sub saveRow (.....)

If blnNewUpdate = True Then
   me.surverytableadapter.update(....)
   blnNewUpdate = False
ElseIf blnNewUpdate = False Then
   Messagebox.Show("Sorry, existing records cannot be updated")
End If

In fact, there are many alternatives - another would be put everything into 1 panel, and disable that panel. Therefore no changes can be made to any of the data. When you click the add new button, the panel becomes Enabled, enter the data, and when saved, the panel disables again.....

Just some ideas ;)
 
If the RowState of the selected DataRow is Unchanged then it's been loaded from the database. If it's Added then it's just been added to the DataTable. If it's Detached then it hasn't even been added to the DataTable yet.
 
I'm using VB 2005 with a SQL Server 2000. I have an application that is working well but it currently allows users to edit existing records (which we don’t want). In MS Access you could just set the "Allow Edits" property to false, but that’s not an option in VB with SQL. Does anyone know how I can lock down each record after it is added so it cannot be modified?

You'd remove the update command from the TableAdapter, or call GetChanges(Added + Deleted) when you go to update, or make any records readonly as the user navigates to them in the datatable, if the rowstate is Unchanged
 
Back
Top