I built an application which displays the records from database in the window and checks the the database for new records every couple of seconds. The problem is that the window blinks each time I check for new records and I want to fix it. I have tried to compare the old datatable with the new one and refresh only if they are different. Does anyone know what is the best practice for such cases? I tried to do it the following way but it doesn’t work:
private bool GetBelongingMessages() { bool result = false; DataTable dtTemp = OleDbWorks.GetBelongingMessages(currentCallID); if(dtTemp != dtMessages) { dtMessages = dtTemp; result = true; } else { result = false; } return result; }
First off, it’s important to recognize that what you’re comparing in your code is the references of the datatables, not the contents of the datatables. In order to determine if both datatables have the same contents, you’re going to have to loop through all of the rows and columns and see if they’re equal: