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();
             }

}
}
8
  • 2
    Aside from the error you prob. dont want to show the success message before you actually save it.. Commented Mar 11, 2013 at 3:01
  • 1
    You might want to post some details about the error... Commented Mar 11, 2013 at 3: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 :) Commented Mar 11, 2013 at 3:03
  • already solved it. hahaha! I really misspell things. xD How can I update records in listview with MySQL? Commented Mar 11, 2013 at 3:20
  • 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? Commented Mar 11, 2013 at 6:16

1 Answer 1

2

Set this to solve your problem:

cmd.CommandTimeout = 5000000
Sign up to request clarification or add additional context in comments.

2 Comments

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.
@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.

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.