0
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");
        }
4

1 回答 1

3

不是在这里@Avaiability代替@Availability吗?

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

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

谢谢。

于 2012-08-09T02:57:10.520 回答