none
Winforms:Update multiple windows after insert update delete RRS feed

  • Question

  • Hi,

    I have a windows form that displays search results in datagridview bound to a binding source. User can add/edit/delete records in a different form(double clicking record opens a new form) or in the grid view itself. Everything works fine except when user opens 2 windows of the same search form simultaneously. If user adds/updates or deletes any record in one instance, the same doesnt refresh on the other window, unless user closes the window and searches again. How can I ensure this to happen?

    I guess, since these are 2 different instances using their instance of the datatable, adapter etc, they would not know of any operation happening with the other instance. How can I make the adapter fill themselves up when insert/update/delete happens?? Something of messaging or any another good approach to handle these things.

     

    Thanks in advance. I need to do this rather urgently.

    Friday, June 13, 2008 3:12 PM

Answers

  •  

    My suggestions:

     

    option 1: define sort of global 'update' event, and register each for to listen on it. every time data is changed in one form, raise the event to update the others and reload the data.

    This solution will work within single application process/instance.

     

    option 2: use periodic refresh on the forms, just force refresh every N seconds

     

    option 3: if you are connecting to Microsoft SQL Server 2005 or later, use SqlDependency feature.

    SqlDependency allows you to listen for changes for changes on SQL table. This works only with Microsoft SQL Server 2005 or later. It will not work with other SQL servers. Search MSDN and Internet for documentation and code samples.

    This will work cross process/machine as well, aka changes in one application instance/process will raise notification in all the others listeners.

     

    If your database is not a Microsoft SQL server, check if it have kind of notifications mechanism, like SqlDependency.

     

     

    Let me know if any of the above helps you.

    Wednesday, July 30, 2008 8:52 AM
    Moderator

All replies

  • Mister, any solution about it ?

     

    Thanks.

     

    Wednesday, July 30, 2008 7:13 AM
  •  

    My suggestions:

     

    option 1: define sort of global 'update' event, and register each for to listen on it. every time data is changed in one form, raise the event to update the others and reload the data.

    This solution will work within single application process/instance.

     

    option 2: use periodic refresh on the forms, just force refresh every N seconds

     

    option 3: if you are connecting to Microsoft SQL Server 2005 or later, use SqlDependency feature.

    SqlDependency allows you to listen for changes for changes on SQL table. This works only with Microsoft SQL Server 2005 or later. It will not work with other SQL servers. Search MSDN and Internet for documentation and code samples.

    This will work cross process/machine as well, aka changes in one application instance/process will raise notification in all the others listeners.

     

    If your database is not a Microsoft SQL server, check if it have kind of notifications mechanism, like SqlDependency.

     

     

    Let me know if any of the above helps you.

    Wednesday, July 30, 2008 8:52 AM
    Moderator