我有一个MySQL的插入查询:
mySqlCommand = mySqlConnect.CreateCommand();
mySqlCommand.CommandText = "INSERT INTO MajorEquipment(EquipmentType, PACId, EquipmentNumber, EquipmentDsc) "
+ "SELECT @EquipmentType, (SELECT PACId FROM PlantAreaCodes WHERE AreaCode = @Location), @EquipmentNumber, @EquipmentDsc "
+ "FROM DUAL WHERE NOT EXISTS (SELECT * FROM MajorEquipment "
+ "WHERE EquipmentNumber = @EquipmentNumber;";
mySqlCommand.Parameters.Add("@EquipmentNumber", MySqlDbType.VarChar);
mySqlCommand.Parameters.Add("@Location", MySqlDbType.VarChar);
mySqlCommand.Parameters.Add("@EquipmentType", MySqlDbType.VarChar);
mySqlCommand.Parameters.Add("@EquipDsc", MySqlDbType.VarChar);
mySqlCommand.Parameters["@EquipmentNumber"].Value = MeModel.EquipmentNumber; //string
mySqlCommand.Parameters["@Location"].Value = MeModel.Location; //string
mySqlCommand.Parameters["@EquipmentType"].Value = MeModel.EquipmentType; //string
mySqlCommand.Parameters["@EquipDsc"].Value = MeModel.Notes; //string
mySqlCommand.ExecuteNonQuery(); // error
每当我尝试在这里执行时,我都会
命令执行期间遇到致命错误。
并没有进一步的解释。但是如果我执行完全相同的查询,甚至几乎直接将其剪切并粘贴到MySQL中,它就会顺利执行。发生了什么事?