I'm working on a project where users are able to modify records. So basically a form loads, with roughly 15 fields (textboxes, Comboboxes, etc). The user is able to edit any or all fields on that form. I create a function that saves the original values (on form_Load) to .tag property. Then when user tries to save it, i compare control.tag = control.text and see if the values have changed. It recognizes the smallest of changes, and works seamleassly. Now I'm trying to update these changes in SQL SErver, but I'm not sure what the best idea would be. I'm trying to create a parametized query to update each field, but in this case should I be comparing the .tag to .text for each value, and if it's different then passing the parameter to the UPDATE statement....here's what I mean...
Update tbl1 Set Dept = @Dept
if dept.tag = dept.text
cmd.parameters.addwithvalue(@Dept, sqldptype.text)=txtdept.text
End if
Anyone have any ideas if this is wrong?
Is there another way to do this other than checking if values are different, I feel like this is tedious? then again should I just update all the fields, as long as 'SOME' fields where changed?
Trying to find a best way to do this....this is my function to check if fields are different on UPDATE
Private Function isDirty() As Boolean
IsDirty = False
For Each ctr As Control In grpClientInfo.Controls
If TypeOf ctr Is TextBox Then
If ctr.Tag.ToString <> ctr.Text Then
IsDirty = True
End If
ElseIf TypeOf ctr Is ComboBox Then
If ctr.Tag.ToString <> ctr.Text Then
IsDirty = True
End If
ElseIf TypeOf ctr Is MaskedTextBox Then
If ctr.Tag.ToString <> ctr.Text Then
IsDirty = True
End If
ElseIf TypeOf ctr Is RichTextBox Then
If ctr.Tag.ToString <> ctr.Text Then
IsDirty = True
End If
End If
Next
End Function
then I check the boolean
if isDirty() then
MsgBox "You've made changes....blah blah saving now....
CALL ThisNewUpdateFunction 'yet to be written
else
MSgboX "no changes"
End if