Hi there,
I have a large database with a lot of people in it. I am writing a page to get rid of duplicate people which I want to step through all data, checking if all 61 fields match and if not, prompting the user to pick the value to keep.
I am looping through and checking the values as follows:
For i As Integer = 0 To FinalPersonnel.Fields.Count - 1
Dim NewTable As New DataTable
Dim EntitiesDifferent As Boolean
'
'SNIP
'
'Check against each other entity, populating a datatable with possible values
'
If EntitiesDifferent Then
Dim GS As New GenericGridSelector("Pick a value for " & FinalPersonnel.Fields(i).Name, "Pick a value for " & FinalPersonnel.Fields(i).Name, NewTable)
GS.ShowDialog(Me)
If Not GS.Cancelled Then
Select Case FinalPersonnel.Fields(i).CurrentValue.GetType.ToString
Case "".GetType.ToString
FinalPersonnel.Fields(i).CurrentValue = CType(NewTable.Rows(GS.SelectedIndex)(0), String)
Case Now.GetType.ToString
FinalPersonnel.Fields(i).CurrentValue = CType(NewTable.Rows(GS.SelectedIndex)(0), Date)
Case True.GetType.ToString
FinalPersonnel.Fields(i).CurrentValue = CType(NewTable.Rows(GS.SelectedIndex)(0), Boolean)
Case 1.GetType.ToString
FinalPersonnel.Fields(i).CurrentValue = CType(NewTable.Rows(GS.SelectedIndex)(0), Integer)
Case Else
MsgBox("Type problem - " & FinalPersonnel.Fields(i).CurrentValue.GetType.ToString)
End Select
End If
End If
Next
FinalPersonnel.Save()
This didn't work so I did some looking around and added the following before the FinalPersonnel.Save() call:
Dim ComparingPersonnel As New PersonnelEntity(FinalPersonnel.PersonnelId)
FinalPersonnel.Fields.CloneAsDirty()
For i As Integer = 0 To FinalPersonnel.Fields.Count - 1
If Not FinalPersonnel.Fields(i).CurrentValue = ComparingPersonnel.Fields(i).CurrentValue Then
FinalPersonnel.Fields(i).IsChanged = True
End If
Next
With or without the FinalPersonnel.Fields.CloneAsDirty() it didn't work and it ignored any selections I made.
I turned the TraveLevel to Verbose just for the save call and it didn't put anything into the Immediate Window
This is bound to be a one liner to fix, I just don't know how to do it!