I am running into issues with an application that I wrote. Basically it is a month calendar that is made out of panels/listboxes for each day of the month. I populate my listboxes using the following:
private void PopulateEventListBoxes(int offsetNumber, int monthDays)
{
string locationSelected = this.LocationComboBox.Text.ToLower();
for (int i = 0; i <= (monthDays - 1); i++)
{
DateTime dateSelected = Convert.ToDateTime(m_ArrayDateLabel[offsetNumber + i].Text).Date;
var tempCalendar = new Data.DataSet.vwGet_CalendarDetailsDataTable();
switch (locationSelected)
{
case "all":
Data.Manager.CalendarDetailsTableAdapter.FillByDate(tempCalendar, dateSelected);
break;
default:
Data.Manager.CalendarDetailsTableAdapter.FillByDateCity(tempCalendar, dateSelected, locationSelected);
break;
}
foreach (Data.DataSet.vwGet_CalendarDetailsRow row in tempCalendar)
{
((ListBox)m_ArrayEventListBox[offsetNumber + i]).Items.Add(row.Name + " - " + row.StatusCode);
}
}
}
I am using the var tempCalendar = new Data.DataSet.vwGet_CalendarDetailsDataTable(); for the DataTable because I need to load the day events into each of the listboxes. This data is coming from SQL server from a view.
Once the Calendar loaded, the users have the ability to Add/Edit/Delete items through a pop-up Dialog with the Calendar details for the day. When the Dialog loads to Add/Edit I populate it this way:
private void SearchForEventsByDate()
{
switch (m_LocationSelected)
{
case "all":
Data.Manager.CalendarDetailsTableAdapter.FillByDate(DataSetCalendar.vwGet_CalendarDetails, m_DateSelected);
CalendarDetailsBindingSource.DataSource = DataSetCalendar.vwGet_CalendarDetails;
break;
default:
Data.Manager.CalendarDetailsTableAdapter.FillByDateCity(DataSetCalendar.vwGet_CalendarDetails, m_DateSelected, m_LocationSelected);
CalendarDetailsBindingSource.DataSource = DataSetCalendar.vwGet_CalendarDetails;
break;
}
RefreshRepRecordCount();
}
This time when load the data, I am using the call DataSetCalendar.vwGet_CalendarDetails instead of a temp memory version of the datatable.
My issue is coming into play if I follow these procedures:
- Add new event for an employee
- Delete that same event that I just added
- Try and re-add new event for the employee on the same day – the app throws an error that the GUID is already present in the table.
My table’s primary key is EventDate and EmployeeGuid. If I query the SQL table after the delete, there is no record but my application still thinks the record still exists. I know that the record is in the memory.
I have tried the following to remove it from memory but it is not working:
DataSetCalendar.vwGet_CalendarDetails.FindByEmployeeGUID(SelectedCalendarEvent.EmployeeGUID).Delete();
DataSetCalendar.vwGet_CalendarDetails.AcceptChanges();
I have also tried using Remove to get rid of the record but my app still think the record exists. I don’t know what else to do or try. Any help would be great.
I was able to fix this by adding the
Clear()