title: Call method from another class in C#
body: <p>I have a problem with my C# application and I don't know how to deal with that. It's an app for my studies and it's first time I am using a C# and Visual Studio.</p>
  
  <p>So - I have main form <code>Form1</code> with a MenuStrip where I can go to another forms (which are datatables from my dataset displayed in a DataGridView). I can work in connectionless mode (writing data to .xml file) and in connection mode (sync directly to my database). 
  In main form I have a <code>Switch_btn</code> button where I can change a mode I am working in. It's using a class:</p>
  
  <pre><code>public static class Connection_mode
      {
          public static int connection = 0;
      }
  </code></pre>
  
  <p>It's just changing the value of one variable like that:</p>
  
  <pre><code>Connection_mode.connection = 1;
  </code></pre>
  
  <p>In another form (class) <code>Function</code> I have a method which updates a database:</p>
  
  <pre><code>public void MethodToExec()
          {
              this.ds.WriteXml("D:\\sth.xml");
              this.dataSet_baza.Tables["funkcja"].Merge(funkcjaTable);
              this.funkcjaTableAdapter.Update(dataSet_baza.funkcja);
          }
  </code></pre>
  
  <p>When I am in connectionless mode I have a local DataTable on which I am making changes. And in this form it's working and send all data from local table to the database - it's nice. </p>
  
  <p>And it's my main question:
  I want to sync data with a database when I click a <code>Switch_btn</code> in main <code>Form1</code>. I can have all other forms closed but when I click Switch I want to exec the <code>MethodToExec()</code> from <code>Function</code> form.</p>
  
  <p>I've tried sth like that in <code>Switch_btn</code> code:</p>
  
  <pre><code>var funkcja = new Function();
  funkcja.MethodToExec();
  </code></pre>
  
  <p>But it's not updating the database.</p>
  
  <p>Maybe there is better way to do that but I don't know how.</p>