Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Mysql Insert Data not work
    primarykey
    data
    text
    <p>I am Nubie in C#, I Try to learn CRUD. Select data Succes but I cant Save data to mysql. my table</p> <pre><code>mahasiswa ID| namae | jurusan | email _____________________________ 1 | Bill | IT | bill@gmail.com 2 | Tony | IT | Tony@gmail.com </code></pre> <p>ID is set to auto increment in Mysql</p> <p>and this my script for btn save</p> <pre><code> void btnsave_Click(object sender, EventArgs e) { try { if (txtid.Text != "" &amp;&amp; txtnama.Text != "" &amp;&amp; txtjurusan.Text != "" &amp;&amp; txtemail.Text != "") { query = string.Format("INSERT INTO mahasiswa values ('{1}','{2}','{3}');", txtnama.Text, txtjurusan.Text, txtemail.Text); koneksi.Open(); perintah = new MySqlCommand(query, koneksi); adapter = new MySqlDataAdapter(perintah); int res = perintah.ExecuteNonQuery(); koneksi.Close(); if (res == 1) { MessageBox.Show("Input Data Sukses..."); } else { MessageBox.Show("Input Data Gagal... "); } } else { MessageBox.Show("Data tidak lengkap"); } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } </code></pre> <p>That Script can run, but after input data and click save buttonm the program stop.</p> <p>Can anybody help me.</p> <p>Im very Appreciated your answer</p> <p>Thanks</p> <p>form load</p> <pre><code> void Form1_Load(object sender, EventArgs e) { try { koneksi.Open(); query = string.Format("SELECT * FROM mahasiswa"); perintah = new MySqlCommand(query, koneksi); adapter = new MySqlDataAdapter(perintah); perintah.ExecuteNonQuery(); ds.Clear(); adapter.Fill(ds); koneksi.Close(); dgv1.DataSource = ds.Tables[0]; dgv1.Columns[0].Width = 50; dgv1.Columns[0].HeaderText = "ID"; dgv1.Columns[1].Width = 120; dgv1.Columns[1].HeaderText = "Nama Mahasiswa"; dgv1.Columns[2].Width = 120; dgv1.Columns[2].HeaderText = "Jurusan"; dgv1.Columns[3].Width = 120; dgv1.Columns[3].HeaderText = "Email"; //txtid.clear(); txtnama.Clear(); txtjurusan.Clear(); txtemail.Clear(); btnedit.Enabled = false; btndelete.Enabled = false; btnsave.Enabled = true; btnsearch.Enabled = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload