title: SqlDependency Slow performance
body: <p>I use query notification of <code>SqlDependency</code> and here's the scenario:</p>
  
  <p>I have a small table with 100 records but quite large data inside these records</p>
  
  <p>Here's the code:</p>
  
  <pre><code>private void AutoUpdate()
  {
      SqlDependency.Stop(connectionstring);
      SqlDependency.Start(connectionstring);
  
      using (SqlConnection cn = new SqlConnection(connectionstring))
      {
          using (SqlCommand cmd = cn.CreateCommand())
          {
              cmd.CommandType = CommandType.Text;
              cmd.CommandText = @"Select [Number], [Creation date],[Createdby], [Approved]  from  [dbo].[MyTable] Order By Number";
  
              dt = new DataTable();
              cmd.Notification = null; 
              SqlDependency dep = new SqlDependency(cmd); 
              dep.OnChange += new OnChangeEventHandler(dep_OnChange); 
              cn.Open(); 
  
              using (SqlDataReader dr = cmd.ExecuteReader())
              {
                  dt.Load(dr);
              }
  
              dataGridView1.DataSource = dt;
          }
      } 
  }
  </code></pre>
  
  <p>and for the <code>OnChange</code> event I use the following code</p>
  
  <pre><code>private void dep_OnChange(object sender, SqlNotificationEventArgs e)
  { 
      if (this.InvokeRequired)
      {
          dataGridView1.BeginInvoke(new MethodInvoker(AutoUpdate)); 
      }
      else
      { 
          AutoUpdate(); 
      }
  
      SqlDependency dep = sender as SqlDependency;
      dep.OnChange -= new OnChangeEventHandler(dep_OnChange);
  }
  </code></pre>
  
  <p>I also use the <code>CellValueChanged</code> event to trigger if the user changes any value in my Datagridview</p>
  
  <p>The problem is: when the user changes the value of one cell, it updates the database and then fires the <code>OnChange</code> event which cause to reload all the datatable with all records</p>
  
  <p>Imagine that the user wants to fill the <code>NUMBER</code> field with the value '0' for the first 50 record</p>
  
  <p>The user will simply press down arrow then the key 0 on keyboard continuously, and that will cause a huge amount of data to be sent and received, because the application will receive the datatable from the database after every press, and while trying this I experienced a very slow performance</p>
  
  <p>Is there a better approach to implement query notification? </p>
  
  <p>Is there a way to make the <code>OnChange</code> event works only on the affected row? not the whole table?</p>