ajanuskevicius
9/12/2016 - 2:42 PM

C# Database Insert

C# Database Insert

MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=kodasdell;database=dev_db");

private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "" && textBox2.Text != "" && textBox3.Text != "") {

                MySqlCommand cmd = new MySqlCommand("INSERT INTO dev_table VALUES ("
                    + textBox1.Text
                    + ",'"
                    + textBox2.Text
                    + "','"
                    + textBox3.Text
                    + "')", con);

                con.Open();
                cmd.ExecuteNonQuery();
                MessageBox.Show("Success!");
                con.Close();
            }
            else { MessageBox.Show("There is empty field(s)!"); }
        }