title: How do I capture the value of a text box and use it as a variable?
body: <p>Let me preface this by saying I am very new to C# and I am converting a program from VB.net to C#.  </p>
  
  <p>I'm working in <code>Visual Studio 2012</code> and running a <code>SQL Server 2008R2</code></p>
  
  <p>OK, So I have a form, Form1. on this form is a Text box a user can fill out, TextBox1.  Now I want to use the information in the text box as a variable to pull information from a database and populate a text box (textbox2) on a different form (form2) this is the code I am currently using on form 2</p>
  
  <pre><code>    private void form2_Load(object sender, EventArgs e)
      {
  
          string Name = Form1.TextBox1.Text;
          this.TBMainTableAdapter.FillBy(Name);
  
      }
  </code></pre>
  
  <p>I've also tried loading it like this:  </p>
  
  <pre><code>this.TBMainTableAdapter.FillBy(Form1.TextBox1.Text);
  </code></pre>
  
  <p>these both give me the  "Object reference is required for a non-static field... error</p>
  
  <p>In VB.Net it was a lot easier, I coded it like this, and it worked perfectly.</p>
  
  <pre><code>Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  Me.TBMainTableAdapter.FillBy(Me.ProjectDataset.TBName, TextBoxName.Text)
  End Sub
  </code></pre>
  
  <p>Is there something I am missing in the code behind? I tried changing the code on the text box </p>
  
  <p>from </p>
  
  <pre><code>public System.Windows.Forms.TextBox TextBox1;
  </code></pre>
  
  <p>to </p>
  
  <pre><code>public static System.Windows.Forms.TextBox TextBox1;
  </code></pre>
  
  <p>While this cleared up the errors on pulling the variable, it threw a bunch more errors in the code-behind on form 1, the "cant be accessed with an instance, give it a nametype" error</p>
  
  <p>Would it be worth it to change all the errors on the code behind. and more importantly is that the right way to do this?</p>
  
  <hr>
  
  <p>OK so I added these 2 under</p>
  
  <pre><code>public partial class Form1 : Form
  Form1  form1;
  public Form2(Form1 frm)
  
      {    
          form1 = frm;
      }
  
      Form2 frm = new Form1(this);
  </code></pre>
  
  <p>Im getting the "Method must have a return type error" at the "Public Form2(Form1 frm)" line
  and
  "error Namespace.Form1 does not have a constructor that takes 1 arguments" at the Form2 frm = new Form1(this); line</p>
  
  <p>also if I put the getter property in Form1, I get an error about declaring 2 objects with the same name.  Cant find anywhere that declares TextBox1 except in the code behind where its declared at the very end of the code behind as</p>
  
  <pre><code>public System.Windows.Forms.TextBox TxtBox1
  </code></pre>
  
  <p>and if I put the getter below that, I get an only assignment, call, etc can be used as a statement error</p>