0
我得到了一個插入國家查詢一些代碼,我需要將其更改爲參數,但我收到此錯誤: 請確保所有領域都在正確的格式(數字字段[0- 9],日期[dd/mm/yyyy]SQL格式錯誤
創建國家時我輸入了正確的格式,所以我不知道爲什麼會出現這個錯誤原始的sql查詢被註釋掉了,所以你可以看到我做了修改。
public static int InsertCountry(int Company_ID, string CountryISO, string CountryName, int Currency, int IsActive, int CreatedByUser, string CountryCode, string Operator, string TransitTime, string Departures, string ImportOperator, string ImportTransitTime, string ImportDepartures, decimal? SECAAmt, decimal? SECAPer)
{
int ID = -1;
string sql = "proc_InsertCoutnry";
using (MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(DataUtils.ConnectionStrings["TAT"]))
{
conn.Open();
using (MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(sql, conn))
{
cmd.CommandType = CommandType.Text;
/* cmd.CommandText = "INSERT INTO countries (Company_ID, CountryISO,CountryName,CurrencyID,IsActive,CreatedByUser,CreatedDate,ModifiedByUser,ModifiedDate,CountryCode,Operator,TransitTime,Departures,ImportOperator,ImportTransitTime,ImportDepartures, SECAAmt, SECAPercent) " +
"VALUES(" + Company_ID + ", '" + CountryISO.Replace("'", "''") + "', '" + CountryName.Replace("'", "''") + "'," + Currency + ", " + IsActive + "," + CreatedByUser + ",NOW()," + CreatedByUser + ",NOW(),'" + CountryCode.Replace("'", "''") + "','" + Operator.Replace("'", "''") + "','" + TransitTime.Replace("'", "''") + "','" + Departures.Replace("'", "''") + "','" + ImportOperator.Replace("'", "''") + "','" + ImportTransitTime.Replace("'", "''") + "','" + ImportDepartures.Replace("'", "''") + "', ?SECAAmt, ?SECAPer);SELECT LAST_INSERT_ID();"; */
cmd.CommandText = @"INSERT INTO countries (Company_ID, CountryISO,CountryName,CurrencyID,IsActive,CreatedByUser,CreatedDate,ModifiedByUser,ModifiedDate,CountryCode, Operator,TransitTime,Departures,ImportOperator,ImportTransitTime,ImportDepartures, SECAAmt, SECAPercent) " +
"VALUES(?company_ID, ?countryISO, ?countryName, ?currency, ?isActive, ?createdByUser,NOW(),?createdByUser,NOW(), ?countryCode, ?operator," +
"?transitTime, ?departures, ?importOperator, ?importTransitTime, ?importDepartures, ?SECAAmt, ?SECAPer);SELECT LAST_INSERT_ID();";
cmd.Parameters.Add(new MySqlParameter("company_ID", Company_ID));
cmd.Parameters.Add(new MySqlParameter("countryISO", CountryISO));
cmd.Parameters.Add(new MySqlParameter("countryName", CountryName));
cmd.Parameters.Add(new MySqlParameter("currency", Currency));
cmd.Parameters.Add(new MySqlParameter("isActive", IsActive));
cmd.Parameters.Add(new MySqlParameter("createdByUser", CreatedByUser));
cmd.Parameters.Add(new MySqlParameter("operator", Operator));
cmd.Parameters.Add(new MySqlParameter("transitTime", TransitTime));
cmd.Parameters.Add(new MySqlParameter("departures", Departures));
cmd.Parameters.Add(new MySqlParameter("importOperator", ImportOperator));
cmd.Parameters.Add(new MySqlParameter("importTransitTime", ImportTransitTime));
cmd.Parameters.Add(new MySqlParameter("importDepartures", ImportDepartures));
cmd.Parameters.Add(new MySqlParameter("SECAAmt", SECAAmt));
cmd.Parameters.Add(new MySqlParameter("SECAPer", SECAPer));
ID = int.Parse(cmd.ExecuteScalar().ToString());
}
}
return ID;
}
執行的實際查詢是什麼? –
如果您無法在某些配置中看到內部異常問題,那麼該異常是什麼 – wiretext