According to your description, you noticed the listbox still shows the
record which has been deleted. You suspect this is because
Clearing/ReFilling of the listbox happens before the Access DB has caught
up with what's happening, correct? If I misunderstood anything here, please
don't hesitate to correct me.
Could you please paste some code snippet about how do you
delete/clear/re-filling the listbox?
The delete function in the main app is:
if (diaryRecord.DeleteRecord())
{
FireMessageHandler("Record Deleted", false);
ClearDiaryEventsForm();
Application.DoEvents();
FillDiaryEventsListView();
}
else
{
FireMessageHandler("Unable To Delete Record", true);
}
The delete record function is:
public bool DeleteRecord()
{
return JCalEventUpdater.DeleteRecord(this);
}
which calls:
public static bool DeleteRecord(JDiaryRecord diaryRecord)
{
string delString = "DELETE * FROM ";
delString += m_TableName;
delString += " WHERE RecordNumber = ";
delString += diaryRecord.RecordNumber.ToString();
m_OleDbConnection = GetOleDbConnection();
m_OleDbConnection.Open();
OleDbCommand commandDelete = new OleDbCommand(delString,
m_OleDbConnection);
m_OleDbDataAdapter.DeleteCommand = commandDelete;
try
{
m_OleDbDataAdapter.DeleteCommand.ExecuteNonQuery();
return true;
}
catch
{
return false;
}
}
As you can see I have an Application.DoEvents(); call in the main delete
function ti give Access time to catch up
It sounds like you forget to update your dataset to Access database.
Did you add the code statement (OleDbDataAdapter.update(dataset)) after you
delete the record from cached DataSet?
I don't use any of the graphical data controls and the
FillDiaryEventsListView(); pulls the records directly from the database:
// Returns all index data in an ArrayList
public static ArrayList AllIndexDataAfter(int dateIndex, bool dateOrder)
{
ArrayList alRecords = new ArrayList();
// Create the SelectCommand.
string strSelect = "SELECT RecordNumber, DateIndex, TimeIndex, Details
FROM " + m_TableName;
strSelect += " WHERE DateIndex >= " + dateIndex.ToString();
// TODO Check Ordering
if (dateOrder)
strSelect += " ORDER BY DateIndex, TimeIndex";
else
strSelect += " ORDER BY Details, DateIndex";
// Create Connection
m_OleDbConnection = GetOleDbConnection();
m_OleDbDataAdapter = CreateSelectAdapter(m_OleDbConnection, strSelect);
// Create / Fill the dataset
m_DataSet = new DataSet();
m_OleDbDataAdapter.Fill(m_DataSet, m_TableName);
// Get the Table from the Dataset
m_DataTable = m_DataSet.Tables[0];
JDiaryRecord.JCalEventIndexData indexData;
// Loop through the Dataset and add each Row to the ArrayList
foreach (DataRow dataRow in m_DataTable.Rows)
{
indexData = new JDiaryRecord.JCalEventIndexData();
GetRecordDetailsForIndexdata(dataRow, ref indexData);
alRecords.Add(indexData);
}
return alRecords;
}
As you can see I call Application.DoEvents(); in the first function to
give Access time to catch up
I would appreciate any thoughts.