title: Why doesn't this work for me? c#
body: <p>I try to make a program so I can see how much I use of electricity, water, etc. per year. I've created three forms containing </p>
  
  <ol>
  <li>MainForm</li>
  <li>A form where I can add the data and </li>
  <li>A setting for "MainForm"</li>
  </ol>
  
  <p>On <code>MainForm</code> there is a <code>DataGridView</code> and in a class <code>loadlist.cs</code> I put in the code to load data from SQL Server using a <code>DataTable</code>. </p>
  
  <p>Now I want form 2 to access the <code>loadlist.cs</code> and it works properly - I get a <code>MessageBox.Show()</code> result to check. </p>
  
  <p>But when I want to it add the data to the <code>DataGridView</code>, it doesn't work. </p>
  
  <p>How?</p>
  
  <p>Code from "MainForm.cs":</p>
  
  <pre><code>Jojo op = new Jojo();
  
  Gridview_index.DataSource = GetTable();
  Gridview_index.DataSource = op.JojoGetir("Elforbrug");
  </code></pre>
  
  <p>Code from "loadlist.cs":</p>
  
  <pre><code>public List&lt;GetValues&gt; JojoGetir(string input) {
      AutoClosingMessageBox.Show(input, "Vis", 1000);
  
      List&lt;GetValues&gt; JojoListesi = new List&lt;GetValues&gt;();
  
      string sql = "SELECT * FROM " + input;
  
      con.Open();
      cmd = new SqlCommand(sql, con);
  
      SqlDataReader dr = cmd.ExecuteReader();
  
      while (dr.Read())
      {
          GetValues ogr = new GetValues();
          ogr.Id = Convert.ToInt32(dr [0]);
          ogr.Dato = Convert.ToDateTime(dr [1].ToString());
          ogr.Aflæsning = Convert.ToInt32(dr [2]);
          ogr.Forskel = Convert.ToInt32(dr [3]);
  
          JojoListesi.Add(ogr);
      }
  
      con.Close();
      return JojoListesi;
  }
  </code></pre>
  
  <p>Code from "add.cs":</p>
  
  <pre><code>if (Vaelgforbrug.SelectedItem != null &amp;&amp; 
      string.IsNullOrWhiteSpace(IndtastForbrug.Text) == false) {
      cmd.Connection = cn;
  
      cn.Open();
      MessageBox.Show((DateTime.Parse(datoForbrug.Value.ToShortDateString())).ToString("dd-MM-yyyy"));
  
      cmd.CommandText = "insert into " + Vaelgforbrug.SelectedItem + "forbrug (Dato, Aflæsning, Forskel) VALUES ('" + (DateTime.Parse(datoForbrug.Value.ToShortDateString())).ToString("dd-MM-yyyy") + "', '" + IndtastForbrug.Text + "','" + 0 + "')";
      cmd.ExecuteNonQuery();
  
      AutoClosingMessageBox.Show("Gemt!", "Opsætning", 1000);
      cn.Close();
      Close();
  
      var op = new Jojo();
      var f = new Forbrug();
  
      f.Gridview_index.DataSource = op.JojoGetir(Vaelgforbrug.SelectedItem + "forbrug");
  }
  </code></pre>
  
  <p>From "AutoClosingMessageBox" I get the "input" where I can see it's triggered but no data is entered in "Gridview_index". It saves the data I want to add to SQL Server but not to Gridview_index.</p>