Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do not use string concatenation to build sql command text, use always a parameterized query</p> <pre><code>query = "INSERT INTO mahasiswa VALUES (@p1,@p2,@p3);"; using(MySqlConnection koneksi = new MySqlConnection(connectionString)) using(MySqlCommand perintah = new MySqlCommand(query, koneksi)) { koneksi.Open(); perintah.Parameters.AddWithValue("@p1", txtnama.Text); perintah.Parameters.AddWithValue("@p2", txtjurusan.Text); perintah.Parameters.AddWithValue("@p3", txtemail.Text); int res = perintah.ExecuteNonQuery(); if (res == 1) MessageBox.Show("Input Data Sukses..."); else MessageBox.Show("Input Data Gagal... "); } </code></pre> <p>If you use string concatenation your code will be open to sql injection where a malicious user could wreak havoc with your database (<a href="https://stackoverflow.com/questions/332365/how-does-the-sql-injection-from-the-bobby-tables-xkcd-comic-work">Look at this funny example</a>)</p> <p>Also your format statement is totally wrong, I doubt that your code reaches the point where the database command is executed because you list the arguments for string.Format from the index 1 to index 3 and you supply 3 arguments, but the index should start from zero and end at two. So you should get an exception on that line.</p> <p>Another point to keep note is the <a href="http://msdn.microsoft.com/en-us/library/yh598w02%28v=VS.80%29.aspx" rel="nofollow noreferrer">using statement</a>. As you can see, in my code the using statement will ensure the proper closing and disposing of the connection and command objects. The connection is particularly important to dispose properly because a failure here could break your program later.</p>
    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.
    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