Esempio n. 1
0
        public static DbDataReader ExecuteReader(string commandTextOrSpName, CommandType commandType, IDictionary <string, object> dictionary)
        {
            //sqlDataReader不能用using 会关闭conn 导致不能获取到返回值。注意:DataReader获取值时必须保持连接状态
            SqlConnection_RW conn = new SqlConnection_RW(DbType, ConnString_R, ConnString_RW);
            DbCommandCommon  cmd  = new DbCommandCommon(DbType);

            PreparCommand(conn.DbConnection, cmd.DbCommand, commandTextOrSpName, commandType, dictionary);
            return(cmd.DbCommand.ExecuteReader(CommandBehavior.CloseConnection));
        }
Esempio n. 2
0
 public static int ExecuteNonQuery(string commandTextOrSpName, CommandType commandType, IDictionary <string, object> dictionary)
 {
     using (SqlConnection_RW conn = new SqlConnection_RW(DbType, ConnString_RW))
     {
         using (DbCommandCommon cmd = new DbCommandCommon(DbType))
         {
             PreparCommand(conn.DbConnection, cmd.DbCommand, commandTextOrSpName, commandType, dictionary);//参数增加了commandType 可以自己编辑执行方式
             return(cmd.DbCommand.ExecuteNonQuery());
         }
     }
 }
Esempio n. 3
0
 public static int ExecuteNonQuery(string commandTextOrSpName, CommandType commandType = CommandType.Text)
 {
     using (SqlConnection_RW conn = new SqlConnection_RW(DbType, ConnString_RW))
     {
         using (DbCommandCommon cmd = new DbCommandCommon(DbType))
         {
             PreparCommand(conn.DbConnection, cmd.DbCommand, commandTextOrSpName, commandType);
             return(cmd.DbCommand.ExecuteNonQuery());
         }
     }
 }
Esempio n. 4
0
 public static Task <object> ExecuteScalarAsync(string commandTextOrSpName, CommandType commandType, IDictionary <string, object> dictionary)
 {
     using (SqlConnection_RW conn = new SqlConnection_RW(DbType, ConnString_R, ConnString_RW))
     {
         using (DbCommandCommon cmd = new DbCommandCommon(DbType))
         {
             PreparCommand(conn.DbConnection, cmd.DbCommand, commandTextOrSpName, commandType, dictionary);
             return(cmd.DbCommand.ExecuteScalarAsync());
         }
     }
 }
Esempio n. 5
0
 public static void BatchExecuteNonQuery(IEnumerable <BatchExecuteModel> batchExecuteModels)
 {
     using (SqlConnection_RW conn = new SqlConnection_RW(DbType, ConnString_RW))
     {
         using (DbCommandCommon cmd = new DbCommandCommon(DbType))
         {
             foreach (var item in batchExecuteModels)
             {
                 PreparCommand(conn.DbConnection, cmd.DbCommand, item.CommandTextOrSpName, item.CommandType, item.ParamsDic);
                 cmd.DbCommand.ExecuteNonQuery();
             }
         }
     }
 }
Esempio n. 6
0
 public static DataSet ExecuteDataSet(string commandTextOrSpName, CommandType commandType, IDictionary <string, object> dictionary)
 {
     using (SqlConnection_RW conn = new SqlConnection_RW(DbType, ConnString_R, ConnString_RW))
     {
         using (DbCommandCommon cmd = new DbCommandCommon(DbType))
         {
             PreparCommand(conn.DbConnection, cmd.DbCommand, commandTextOrSpName, commandType, dictionary);
             using (DbDataAdapterCommon da = new DbDataAdapterCommon(DbType, cmd.DbCommand))
             {
                 DataSet ds = new DataSet();
                 da.Fill(ds);
                 return(ds);
             }
         }
     }
 }
Esempio n. 7
0
 /**
  * Update At 2017-3-2 14:58:45
  * Add the ExecuteDataTable Method into Sql_Helper_DG
  **/
 public static DataTable ExecuteDataTable(string commandTextOrSpName, CommandType commandType = CommandType.Text)
 {
     using (SqlConnection_RW conn = new SqlConnection_RW(DbType, ConnString_R, ConnString_RW))
     {
         using (DbCommandCommon cmd = new DbCommandCommon(DbType))
         {
             PreparCommand(conn.DbConnection, cmd.DbCommand, commandTextOrSpName, commandType);
             using (DbDataAdapterCommon da = new DbDataAdapterCommon(DbType, cmd.DbCommand))
             {
                 DataSet ds = new DataSet();
                 da.Fill(ds);
                 if (ds.Tables.Count > 0)
                 {
                     return(ds.Tables[0]);
                 }
                 return(default(DataTable));
             }
         }
     }
 }