Esempio n. 1
0
 public static void ExecuteCommand(string commandName, Action <DataCommand> exec)
 {
     TryDo <DataCommand>(() =>
     {
         exec(DataCommandDetector.GetDataCommand(commandName));
         return(null);
     });
 }
Esempio n. 2
0
 public static int ExecuteNonQuery(string commandName, IDataParameter[] dps)
 {
     return(TryDo(() =>
     {
         DataCommand dataCommand = DataCommandDetector.GetDataCommand(commandName);
         BuilderCommandParame(dps, dataCommand);
         return dataCommand.ExecuteNonQuery();
     }));
 }
Esempio n. 3
0
        public static T ExecuteDataReader <T>(string commandName, IDataParameter[] dps, Func <IDataReader, T> executeRead)
        {
            return(TryDo(() =>
            {
                DataCommand dataCommand = DataCommandDetector.GetDataCommand(commandName);

                BuilderCommandParame(dps, dataCommand);

                if (executeRead != null)
                {
                    using (IDataReader reader = dataCommand.ExecuteDataReader())
                    {
                        return executeRead(reader);
                    }
                }
                return default(T);
            }));
        }
Esempio n. 4
0
 public static T ExecuteScalar <T>(string commandName, IDataParameter[] dps)
 {
     return(TryDo(() =>
     {
         T result = default(T);
         DataCommand dataCommand = DataCommandDetector.GetDataCommand(commandName);
         BuilderCommandParame(dps, dataCommand);
         object obj = dataCommand.ExecuteScalar();
         try
         {
             if (obj != null)
             {
                 result = (T)obj;
             }
         }
         catch
         {
             result = default(T);
         }
         return result;
     }));
 }