title: button send parameter to the method
body: <p>Hi I have some method which send me data from sql table and I want that - when I click button in datagridview - that send parameter to the method and parameter will have ID value(like on picture 107 or 106). Below on the picture is datagridview with 2 buttons and ID column.</p>
  
  <p><a href="https://i.stack.imgur.com/veEyG.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/veEyG.jpg" alt="enter image description here"></a></p>
  
  <pre><code>public ObservableCollection&lt;MyClass&gt; ReadUpdate(int id_update)
  {
  ObservableCollection&lt;MyClass&gt; result = new ObservableCollection&lt;MyClass&gt;();
  string nwConn = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
  SqlDataReader dr;
  SqlConnection conn = new SqlConnection(nwConn);
  try
  {
  SqlCommand cmd = new SqlCommand();
  cmd.CommandType = CommandType.StoredProcedure;
  cmd.Connection = conn;
  cmd.CommandText = "Insert_Update";
  cmd.Parameters.AddWithValue("@id_update", id_update);
  conn.Open();
  dr = cmd.ExecuteReader();
  while (dr.Read())
  {
  MyClass lin = new MyClass();
  
  lin.id = dr.GetInt32(1);
  if (!dr.IsDBNull(2)) lin.other = dr.GetString(2);
  if (!dr.IsDBNull(3)) lin.barkod = dr.GetString(3);
  if (!dr.IsDBNull(4)) lin.pw = dr.GetInt32(4);
  
  result.Add(lin);
  }
  dr.Close();
  return result;
  
  }
  catch (SqlException e)
  {
  MyClass lin = new MyClass();
  lin.other = e.Message;
  
  result.Add(lin);
  return result;
  
  }
  finally
  {
  conn.Close();
  
  };
  }
  </code></pre>
  
  <p>My class:</p>
  
  <pre><code> public class PIS
  {
  public int ID { get; set; } 
   }
  </code></pre>
  
  <p>And my button:</p>
  
  <pre><code>private void btnUpdate_Click(object sender, System.Windows.RoutedEventArgs e)
  {
  pis_update = (PIS)((Button)sender).DataContext;
  ChildWindow_Update childWindow_update = new ChildWindow_Update();
  childWindow_update.DataContext = ((Pismo)((Button)sender).DataContext).Id_Pismo;
  childWindow_update.Closed += ChildWindow_Update_Closed;
  childWindow_update.Show();
  } 
  
  public ChildWindow_Update()
  {
  InitializeComponent();
  ServiceReference1.Service1Client webService = new ServiceReference1.Service1Client();
  webService.ReadUpdateAsync((int)this.DataContext);
  webService.ReadUpdateCompleted += WebService_ReadUpdateCompleted; 
  
  private void WebService_ReadUpdateCompleted(object sender, ServiceReference1.ReadUpdateCompletedEventArgs e)
  {
  if (e.Result != null)
  {
  //do something
  
  }
  } 
  </code></pre>
  
  <p>I have error in webService.ReadUpdateAsync((int)this.DataContext);
  "Null REference Exception".</p>