It is necessary to update datagridview on changing the table in the database. Several people work in the software at the same time, it is necessary that if one makes a change, the second one sees it immediately. I thought to create a table and monitor the number of records once every 10 seconds, for example, if someone does something parallel to do an insert into it and if the old count does not match the new one, then update the datagridview, but this solution seems to me to load software heavily and it looks strong crutch Is it possible to write a service so that it can update the datagridview on the state of the database?

  • What kind of DBMS is used? Two or three stars? Users and databases in the local network or ...? - Alexander Petrov
  • A two or three star is not quite understood. MSSQL DB, users and DB are in the same local network. - Winteriscoming

1 answer 1

To get changes from SqlServer, you can use the SqlDependency class.

However, it is not necessary to create this relationship between the DBMS and each client application. You must have a dedicated application server (what you call a service) that will receive notifications of changes in SqlServer. And already this application server sends change messages to all clients.

Well and further, the client, having received the notification, addresses with request for obtaining new data.

  • The database is on a dedicated server, the software is on each user on the PC. As I understand it, I need to create a service on the server where the database is, this service should send a request to each software and, according to this request, update for example datagridview. - Winteriscoming
  • @Winteriscoming - Something like this, yes. - Alexander Petrov
  • You do not have an example by chance, I am new to C #, I have never created a service, I understand something about how it will be, but if I had some kind of example, I would use it as a “manual”. - Winteriscoming