title: Sending data from childwindow to parentwindow
body: <p>I did a small library HomeDAL where I have a class with functions like connect,disconnect,add,delete,showbooks etc. to manage my database.</p>
  
  <p>Now I'm doing a client in WPF.  In <code>MainWindow</code>, I have a variable of this class from my HomeDAL, and I have a <code>Button</code> "Add new record".  Clicking on this button opens a new window, where I have some <code>TextBox</code>es to describe the new record and a <code>Button</code> "Make".  Clicking this "Make" button, I close the second window.</p>
  
  <p>I want to use the variable <code>HomeDAL</code> in <code>MainWindow</code> to run one of their functions but it doesn't work, and the application crashes.</p>
  
  <p>Below is a function I have in the second window:</p>
  
  <pre><code>private void btnOkClicked(object sender, RoutedEventArgs e)
  {
      MainWindow test = (MainWindow)this.Parent;
      Book newBook = new Book()
      {
          Tytul = tbTytul.Text,
          Autor = tbAutor.Text,
          Cena = Int32.Parse(tbCena.Text),
          Przeczytane = tbPrzeczytane.Text
      };
      test.SqlConn.InsertBook(newBook);
      this.Close();
  }   
  </code></pre>
  
  <p>Any tip as to why my program crashes?</p>