//public DbConnection conn { get; set; } /// <summary> /// 用于执行没有返回数据的SQL语句,如UPDATE或INSERT、DELETE类 /// </summary> /// <param name="sql"></param> /// <param name="pars"></param> /// <returns></returns> public int ExecuteNonQuery(string sql, Dictionary <string, object> pars) { try { var conn = GetNewConnection(); conn.Open(); var cmd = factory.CreateCommand(); cmd.Connection = conn; cmd.CommandText = sql; foreach (var key in pars.Keys) { cmd.Parameters.Add(new OracleParameter(key, pars[key])); } var result = cmd.ExecuteNonQuery(); conn.Close(); return(result); } catch (Exception e) { LogHelper.Error(e); LogHelper.Info("SQL:" + sql); throw; } }
public int ExecuteNonQuery(string sql, Dictionary <string, object> pars) { try { if (conn.State == ConnectionState.Closed) { conn.Open(); } var cmd = factory.CreateCommand(); cmd.Connection = conn; cmd.CommandText = sql; foreach (var key in pars.Keys) { cmd.Parameters.Add(new OracleParameter(key, pars[key])); } return(cmd.ExecuteNonQuery()); } catch (Exception e) { Console.Out.WriteLineAsync(e.Message); Console.Out.WriteLineAsync("SQL:" + sql); throw; } }