I've tried so hard to insert data on MySql server using this code :
private void button1_Click(object sender, EventArgs e)
{
string con = "datasource=localhost;database=test;port=3307;username=root;password=root";
MySqlConnection sq = new MySqlConnection(con);
sq.Open();
try
{
MySqlCommand com1 = new MySqlCommand("Insert into customerinfo(ID) values('" + textBox1.Text + "')", sq);
com1.ExecuteNonQuery();
//sq.Open();
}
catch (Exception ex)
{
MessageBox.Show("please, enter an ID with at most 3 characters !");
}
try
{
MySqlCommand com2 = new MySqlCommand("Insert into customerinfo(OwnerName) values('" + textBox6.Text + "')", sq);
com2.ExecuteNonQuery();
//sq.Open();
}
catch (Exception ex)
{
MessageBox.Show("please, enter a name with at most 30 characters !");
}
}
The first try brackets are being excuted well, but for the second try, it throws an exeption! Please help me to know why is this happen?