title: Insert into table and Inner Joining 2 tables in C# Form
body: <p>So I have 4 tables in MySql database, we are going to focus on 2 tables for now.
  I have materijal(Material) table and Skart(Scrap) table:</p>
  <p>materijal Table (original) witch has :</p>
  <p>idmaterijal(INT),
  naziv_materijala(VARCHAR),
  kolicina_materiala(FLOAT),
  mjerna_jedinica(VARCHAR),
  sifra_materijala(INT)</p>
  <p>material Table(eng) :</p>
  <p>idmaterial(INT) ,
  name_material(VARCHAR) ,
  quantity_material(FLOAT) ,
  measuring_unit(VARCHAR) ,
  code_material(INT)</p>
  <p>skart Table (original) which has:</p>
  <p>idskart(INT),
  materijal_idmaterijal(INT),
  kolicina_skarta(FLOAT)</p>
  <p>scrap Table (eng):</p>
  <p>idscrap(INT),
  material_idmaterial(INT),
  quantity_scrap(FLOAT)</p>
  <p>They are connected with Non-Identifying Relation 1:1, as you can see in this picture  <a href="https://prnt.sc/hdvGuXJWNI0Q" rel="nofollow noreferrer">https://prnt.sc/hdvGuXJWNI0Q</a>  .
  I want to Insert materijal_idmaterijal into skart table by choosing the name via comboBox, and kolicina_skarta via textBox, as shown in these pictures :</p>
  <p><a href="https://prnt.sc/kbXdQTSJ-wwt" rel="nofollow noreferrer">https://prnt.sc/kbXdQTSJ-wwt</a> - Choosing data on comboBox witch is connected to materijal table and list all naziv_materijal
  <a href="https://prnt.sc/BMvlle9M9OPI" rel="nofollow noreferrer">https://prnt.sc/BMvlle9M9OPI</a>  - Input data in myForm<br />
  <a href="https://prnt.sc/4rF1Ht30PDNL" rel="nofollow noreferrer">https://prnt.sc/4rF1Ht30PDNL</a>  - What happens when I click &quot;Snimi&quot; button (INSERT)</p>
  <p>This is my code for &quot;Snimi&quot; button :</p>
  <pre><code>private void button13_Click(object sender, EventArgs e) // Snimanje Skarta I Update materijal tabele
          {
              konekcija.Open();
              //OleDbCommand komanda = new OleDbCommand();
              MySqlCommand komanda = new MySqlCommand();
              komanda.Connection = konekcija;
              komanda.CommandType = CommandType.Text;
              komanda.CommandText = &quot;INSERT INTO skart(materijal_idmaterijal, value) value(select materijal_idmaterijal from materijal WHERE naziv_materijala = '&quot; + comboBox1.Text + &quot;') AND (kolicina_skarta, value) value('&quot; + textBox7.Text + &quot;') &quot;; 
              komanda.CommandText = &quot;UPDATE materijal SET kolicina_materijala = kolicina_materijala - '&quot; + textBox7.Text + &quot;' WHERE naziv_materijala = '&quot; + comboBox1.Text + &quot;' AND kolicina_materijala &gt;= '&quot; + textBox7.Text + &quot;'&quot;;
              komanda.ExecuteNonQuery();
              konekcija.Close();
              comboBox1.Text = &quot;&quot;;
              textBox7.Text = &quot;&quot;;
              MessageBox.Show(&quot;Uspjesno ste unijeli izabrani Škart&quot;);
          }
  </code></pre>
  <p>And this is my &quot;Osvježi&quot; or on Eng &quot;Refresh&quot; button witch refreshes the dataGridView in my Skart panel :</p>
  <pre><code>private void button12_Click(object sender, EventArgs e) // Osvježi Skart
          {
              konekcija.Open();
              // OleDbCommand komanda = new OleDbCommand();
              MySqlCommand komanda = new MySqlCommand();
              komanda.Connection = konekcija;
              komanda.CommandType = CommandType.Text;
              komanda.CommandText = &quot; SELECT naziv_materijala, s.kolicina_skarta, mjerna_jedinica, sifra_materijala FROM skart AS s INNER JOIN materijal AS m ON s.materijal_idmaterijal = m.idmaterijal; &quot;;
              komanda.ExecuteNonQuery();
              DataTable dt = new DataTable();
              //OleDbDataAdapter da = new OleDbDataAdapter(komanda);
              MySqlDataAdapter da = new MySqlDataAdapter(komanda);
              da.Fill(dt);
              dataGridView3.DataSource = dt;
              konekcija.Close(); 
          }
  </code></pre>
  <p>It uses Inner Join to merge naziv_materijala, s.kolicina_skarta, mjerna_jedinica, sifra_materijala from materijal table into skart table via idmaterijala.
  I want to Insert materijal_idmaterijal into skart table by choosing the name of the naziv_materijal via comboBox, and kolicina_skarta by inserting number in textBox .
  The codes up there are my own and it updates kolicina_materijala (eng . quantity_material) in materijal table but it doesn't insert data in skart table. Please Help.
  PS: Do keep in mind this is my school project and I am only starting to code in C# and crating Forms, I know my code is not clean and It could look better but I am only concerned on learning how to solve this problem.</p>