I'm trying to insert a data to the MySQL database but before that, I'm trying to check if that data is existing or not. If not, it will insert but if yes it will show a message. I've run this code but it only says "Existing!" even though it doesn't exist.
try
{
conn.Open();
string sql12 = "SELECT * FROM courseandorg where connID = ?connID";
MySqlCommand cmd12 = new MySqlCommand("INSERT INTO courseandorg VALUES (connID, '" + lblCourseAbbrev.Text + "','" + lblOrgName.Text + "','" + lblOrgAbbrev.Text + "', '" + cboStatus.Text + "','" + txtquorum.Text + "')");
MySqlCommand cmd14 = new MySqlCommand(sql12, conn);
cmd14.Parameters.AddWithValue("@connID", txtCOConnID.Text);
int count = Convert.ToInt32(cmd14.ExecuteScalar());
if (count > 0)
{
MessageBox.Show("Existing!");
}
else
{
cmd12.ExecuteNonQuery();
MessageBox.Show("Successfully save!");
}
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
conn.Close();
}