1

When I finish editing the item and click save, it causes an error. The error is: Fatal error encountered during command execution Detailed information would be great.

  private void btnSave_Click(object sender, EventArgs e)
    {
        if (textBox1.Text == "")
        {
            MessageBox.Show("VIN is Empty!", "Don't leave it blank!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            textBox1.Focus();
        }
        else if (MessageBox.Show("Do Want To Save it?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
        {
            Initialize();
            connection.Open();
            MySqlCommand cmd = new MySqlCommand();
            cmd.CommandText = "Insert Into registration_form (VIN, Lst_name, Frst_name, Mddle_name, Sx, Hght, Wght, Address, Occupation, Brthday, Plceof_Birth, Cvl_Status, Nmeof_Father, Nmeof_Mother, Citizenship)" +
                "Values (@VIN, @Lst_name, @Frst_name, @Mddle_name, @Sx, @Hght, @Wght, @Address, @Occupation, @Brthday, @Plceof_Birth, @Cvl_Status, @Nmeof_Father, @Nmeof_Mother, @Citizenship)";
            cmd.Connection = connection;


            cmd.Parameters.Add("@VIN",MySqlDbType.VarChar).Value=textBox1.Text.ToUpper();
            cmd.Parameters.Add("@Lst_name",MySqlDbType.VarChar).Value=textBox2.Text.ToUpper();
            cmd.Parameters.Add("@Frst_name",MySqlDbType.VarChar).Value=textBox4.Text.ToUpper();
            cmd.Parameters.Add("@Mddle_name",MySqlDbType.VarChar).Value=textBox3.Text.ToUpper();
            cmd.Parameters.Add("@Sx",MySqlDbType.VarChar).Value=comboBox1.Text.ToUpper();
            cmd.Parameters.Add("@Hght",MySqlDbType.VarChar).Value=textBox6.Text.ToUpper();
            cmd.Parameters.Add("@Wght",MySqlDbType.VarChar).Value=textBox7.Text.ToUpper();
            cmd.Parameters.Add("@Address",MySqlDbType.VarChar).Value=textBox8.Text.ToUpper();
            cmd.Parameters.Add("@Occupation",MySqlDbType.VarChar).Value=textBox9.Text.ToUpper();
            cmd.Parameters.Add("@Brthday",MySqlDbType.VarChar).Value=dateTimePicker1.Text.ToUpper();
            cmd.Parameters.Add("@Plceof_Birth",MySqlDbType.VarChar).Value=textBox11.Text.ToUpper();
            cmd.Parameters.Add("@Cvl_Status",MySqlDbType.VarChar).Value=textBox5.Text.ToUpper();
            cmd.Parameters.Add("@Nmeof_Father",MySqlDbType.VarChar).Value=textBox10.Text.ToUpper();
            cmd.Parameters.Add("@Nmeof_Mohter",MySqlDbType.VarChar).Value=textBox12.Text.ToUpper();
            cmd.Parameters.Add("@Citizenship", MySqlDbType.VarChar).Value = textBox13.Text.ToUpper();
            MessageBox.Show("Record has been successfully saved", "Saved");
            cmd.ExecuteNonQuery();
        }
        FillListView();
             }

}
}
Bernie
  • 1,489
  • 1
  • 16
  • 27
Rohan21
  • 353
  • 5
  • 9
  • 24
  • 2
    Aside from the error you prob. dont want to show the success message before you actually save it.. – iamkrillin Mar 11 '13 at 03:01
  • 1
    You might want to post some details about the error... – Dmitriy Khaykin Mar 11 '13 at 03:02
  • 2
    Also you misspelled parameter Nmeof_mother in the parameter adding lines, it shows as "Nmeof_mohter" - could be the problem. It's why I like to use real, descriptive words for these types of things :) – Dmitriy Khaykin Mar 11 '13 at 03:03
  • already solved it. hahaha! I really misspell things. xD How can I update records in listview with MySQL? – Rohan21 Mar 11 '13 at 03:20
  • Google. I am sure it's been asked before! – Dmitriy Khaykin Mar 11 '13 at 03:29
  • can't seem to find a good one. :( – Rohan21 Mar 11 '13 at 03:35
  • 1
    What do people have against vowels? Why is `@Frst_name` so much better than `@First_name`? Or is it `@Frost_name`, or `@Forest_name`? Who can be sure? – DeanOC Mar 11 '13 at 06:16
  • See my answer to a related question, where I found this error can be thrown for generic MySQL typos: http://stackoverflow.com/questions/2467603/fatal-error-encountered-during-command-execution-with-a-mysql-insert#11460644 – DanM7 Apr 02 '13 at 15:15

1 Answers1

2

Set this to solve your problem:

cmd.CommandTimeout = 5000000
sashkello
  • 17,306
  • 24
  • 81
  • 109
kumar
  • 36
  • 2
  • 2
    This worked, but would you care to explain at all? `CommandTimeout` represents seconds, so you're setting the timeout to almost 25 days. Why did this work? And why do we have to set the timeout to 24.8 days? Also, when attempting to set it to 5000000, checking it in the watch shows it's limited to 2147483. Your resolution works, but I don't understand it. – BenR Feb 18 '14 at 22:06
  • @BenRecord Basically the operation takes longer than the specified timeout and returns such an exception. That's what I would assume anyway.So increasing the timeout gives the command more time to work with. You can set the timeout to whatever value you want or see reasonable. – Perfection Feb 20 '14 at 14:08