In storing events into an event management system, I am also storing a history of the changes. Because the project specifies the use of MySql, and MySql triggers leave something to be desired, I am using actual code to detect changes. I have the following line of code to see if the support notes field changed, and add a history record accordingly:
....
if (!String.Equals(OldEventInfo.supportNotes, NewEventInfo.supportNotes))
{ ChangesMade.Add(new EventHistoryDataItem("support notes", OldEventInfo.supportNotes, NewEventInfo.supportNotes)); }
....
EventsDataset eds = new EventsDataset();
EventsDatasetTableAdapters.eventhistoryTableAdapter ehta = new EventsDatasetTableAdapters.eventhistoryTableAdapter();
EventsDatasetTableAdapters.eventhistorydataTableAdapter ehdta = new EventsDatasetTableAdapters.eventhistorydataTableAdapter();
Int64 HistoryId = Convert.ToInt64(ehta.InsertQuery(NewEventInfo.id.Value, DateTime.Now, UserId));
eds.eventhistorydata.Clear();
foreach (EventHistoryDataItem thisChange in ChangesMade)
{
EventsDataset.eventhistorydataRow newRow = (EventsDataset.eventhistorydataRow)eds.eventhistorydata.NewRow();
newRow.eventHistoryId = HistoryId;
newRow.field = thisChange.Field;
newRow.oldValue = thisChange.OldValue;
newRow.newValue = thisChange.NewValue;
eds.eventhistorydata.AddeventhistorydataRow(newRow);
}
ehdta.Update(eds.eventhistorydata);
The problem is that I am getting history records for "support notes" with identical values in the before and after. I've looked at other questions on SO about string.equals generating false returns, and I have checked to make sure that the before and after strings were identical, and they are. There are no extra spaces or carriage returns or newlines. They are binary identical.
So, what gives? How is a record ending up in my history that says the value has changed from A to B, but with A and B being identical?