Ejemplo n.º 1
0
        private static void AddParam(IDatabase db, string sql, object parameters, CommandType?commandType)
        {
            db.ClearParameters();
            db.CommandType = commandType;
            string s = sql;

            if (parameters != null)
            {
                if (parameters is IEnumerable <KeyValuePair <string, object> > )
                {
                    IModelToParam toparam = new DicToParam();
                    s = toparam.To(db, sql, parameters);
                }
                else
                {
                    IModelToParam toparam = new ModelToParam();
                    s = toparam.To(db, sql, parameters);
                }
            }
            db.CommandText = s;
        }
Ejemplo n.º 2
0
 private void AddParam(IDbCommand command, string sql, object parameters)
 {
     if (parameters != null && (parameters is IEnumerable <DbParameter> || parameters is IEnumerable <IDataParameter>))
     {
         if (parameters is IEnumerable <DbParameter> )
         {
             var ps = parameters as IEnumerable <DbParameter>;
             foreach (var p in ps)
             {
                 command.Parameters.Add(p);
             }
         }
         else
         {
             var ps = parameters as IEnumerable <IDataParameter>;
             foreach (var p in ps)
             {
                 command.Parameters.Add(p);
             }
         }
         command.CommandText = sql;
     }
     else if (parameters != null && parameters is IEnumerable <KeyValuePair <string, object> > )
     {
         IModelToParam toparam = new DicToParam();
         toparam.To(this, command, sql, parameters);
     }
     else if (parameters != null)
     {
         IModelToParam toparam = new ModelToParam();
         toparam.To(this, command, sql, parameters);
     }
     else
     {
         command.CommandText = sql;
     }
 }