title: C# making SQL query on separate class for form
body: <p>I am trying to make query for datagridview from separate C# class. But I want to add textBox value of form2 on this query. How do I do this? </p>
  
  <p>Usually, if I use </p>
  
  <pre><code>var f2 = Application.OpenForms.ofType&lt;Form2&gt;().Single(); 
  </code></pre>
  
  <p>on form1, I can get textbox value of form2 on form1 but on class, this doesn't work (var gets redlined). I am using windows form, and yes, I am actually using Excel file as database. Help.</p>
  
  <p>I can call query1 string from form2 though.. but I can't get the form2 textbox value to this class test.</p>
  
  <pre><code>namespace test
  {
      class query
      {
          var f2 = Application.OpenForms.OfType&lt;Form2&gt;().Single();
          public const string query1 = "Select * from [Sheet1$A2:Q] where Product like '" + f2.txt_Product.Text + "%'";
      }
  }
  </code></pre>