命令执行期间遇到致命错误

时间:2012-08-09 02:51:22

标签: c# .net mysql database phpmyadmin

private void button1_Click_1(object sender, EventArgs e)
        {
            MySqlConnection con = new MySqlConnection(MyConString);
            con.Close();
            con.Open();
            string m = "INSERT INTO Tools (TCode,TName,Description,
                          Classification,Model,Capacity,Status,Quantity,
                          Avaiability,DatePurchased,DateDelivered) 
                      VALUES (@TCode,@TName,@Description,
                             @Classification,@Model,@Capacity,@Status,@Quantity,
                            @Avaiability,@DatePurchased,@DateDelivered)";
            MySqlCommand cmd = new MySqlCommand(m, con);

            cmd.Parameters.Add("@TCode", MySqlDbType.VarChar).Value = txtCode.Text;
            cmd.Parameters.Add("@TName", MySqlDbType.VarChar).Value = txtName.Text;
            cmd.Parameters.Add("@Description", MySqlDbType.VarChar).Value = txtDesc.Text;
            cmd.Parameters.Add("@Classification", MySqlDbType.VarChar).Value = txtClass.Text;
            cmd.Parameters.Add("@Model", MySqlDbType.VarChar).Value = txtModel.Text;
            cmd.Parameters.Add("@Capacity", MySqlDbType.VarChar).Value = txtCapacity.Text;
            cmd.Parameters.Add("@Status", MySqlDbType.VarChar).Value = txtStat.Text;
            cmd.Parameters.Add("@Quantity", MySqlDbType.VarChar).Value = txtQuantity.Text;
            cmd.Parameters.Add("@Availability", MySqlDbType.VarChar).Value = ttAvail.Text;
            cmd.Parameters.Add("@DatePurchased", MySqlDbType.VarChar).Value = txtDP.Text;
            cmd.Parameters.Add("@DateDelivered", MySqlDbType.VarChar).Value = txtDD.Text;

            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("Successful!", "Message");
        }

1 个答案:

答案 0 :(得分:3)

这里不是@Avaiability而不是@Availability吗?

cmd.Parameters.Add("@Availability", MySqlDbType.VarChar).Value = ttAvail.Text;

请检查哪一列是您列的正确名称:AvaiabilityAvailability

感谢。