2

I am getting the "fatal error encountered during command execution" error message when I am running this part of the code:

private void button1_Click(object sender, EventArgs e)
    {
        MySqlCommand cmd = new MySqlCommand("INSERT INTO clienti(nume, prenume, localitate, cnp, adresa, telefon, email) VALUES(@numen, @prenumep, @locl, @cnpc, @adresaa, @telefont, @emaile); ", conn);

        try
        {
            if (numen.Text.Length > 0 && prenumep.Text.Length > 0 && locl.Text.Length > 0 && adresaa.Text.Length > 0 && telefont.Text.Length > 0 && emaile.Text.Length > 0)
            {
                cmd.Parameters.AddWithValue("@numen", numen.Text);
                cmd.Parameters.AddWithValue("@prenumep", prenumep.Text);
                cmd.Parameters.AddWithValue("@locl", locl.Text);
                cmd.Parameters.AddWithValue("@adresaa", adresaa.Text);
                cmd.Parameters.AddWithValue("@telefont", telefont.Text);
                cmd.Parameters.AddWithValue("@emaile", emaile.Text);
                cmd.ExecuteNonQuery();
            }
            else
                throw new Exception("Completati toate informatiile");
            MessageBox.Show("Clientul " + numen.Text + " a fost adaugat");
            numen.Text = "";
            prenumep.Text = "";
            locl.Text = "";
            adresaa.Text = "";
            telefont.Text = "";
            emaile.Text = "";

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

The info is extracted from some textboxes and it has to be written into the MySQL Database.

Thank you in advance for your help.

1
  • that's mostly cause you are throwing an exception in else part Commented Feb 26, 2017 at 13:05

1 Answer 1

1

You do not assign any value to @cnpc parameter, thus the execution of the prepared statement fails.

Sign up to request clarification or add additional context in comments.

2 Comments

OMG now it is so obvious. Thank you!
In this case plsark the answer ad the accepted one to let other views know that the issue has been resolved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.