Exemplo n.º 1
0
        /// <summary>
        /// 构建 SqlCommand 对象(用来返回一个结果集,而不是一个整数值)
        /// </summary>
        /// <param name="driveType">数据库驱动类型</param>
        /// <param name="connection">数据库连接</param>
        /// <param name="storedProcName">存储过程名</param>
        /// <param name="parameters">存储过程参数</param>
        /// <returns>SqlCommand</returns>
        public static DbCommand CreateDbCommand(this StDbDriveType driveType, DbConnection connection, string storedProcName, DbParameter[] parameters)
        {
            //DbParameter
            DbCommand comm = driveType.CreateDbCommand(connection, storedProcName, CommandType.StoredProcedure);

            if (parameters != null && parameters.Length > 0)
            {
                comm.Parameters.AddRange(parameters);
            }
            return(comm);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 预处理用户提供的命令,数据库连接/事务/命令类型/参数
        /// </summary>
        ///// <param name="cmdType">要处理的DbCommand</param>
        ///// <param name="cmdText">数据库连接</param>
        ///// <param name="cmdParams">一个有效的事务或者是null值</param>
        /// <param name="cmdType">命令类型 (存储过程,命令文本, 其它.)</param>
        /// <param name="cmdText">存储过程名或都T-SQL命令文本</param>
        /// <param name="cmdParams">和命令相关联的DbParameter参数数组,如果没有参数为'null'</param>
        /// <param name="mustCloseConn"><c>true</c> 如果连接是打开的,则为true,其它情况下为false.</param>
        private DbCommand PrepareCmd(CommandType cmdType, string cmdText, DbParameter[] cmdParams, out bool mustCloseConn)
        {
            DbConnection conn = null;
            DbCommand    cmd  = _dbDriveType.CreateDbCommand();// DBClient.GetDbCommand(cmdText);

            if (TransConnectionObj != null)
            {
                conn            = TransConnectionObj.DBTransaction.Connection;
                cmd.Transaction = TransConnectionObj.DBTransaction;
                mustCloseConn   = false;
            }
            else
            {
                conn          = _dbDriveType.CreateDbConnection(_connectionString);
                mustCloseConn = true;
            }
            cmd.CommandText = cmdText;
            cmd.Connection  = conn;
            cmd.CommandType = cmdType;
            AppendParameters(cmd, cmdParams);

            return(cmd);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 创建一个新的DBCommand
 /// </summary>
 /// <param name="driveType">数据库驱动类型</param>
 /// <returns></returns>
 public static DbCommand CreateDbCommand(this StDbDriveType driveType)
 {
     return(driveType.CreateDbCommand(string.Empty, string.Empty, CommandType.Text, null));
 }
Exemplo n.º 4
0
 /// <summary>
 /// 创建一个新的DBCommand
 /// </summary>
 /// <param name="driveType">数据库驱动类型</param>
 /// <param name="connString">数据库连接对象</param>
 /// <returns></returns>
 public static DbCommand CreateDbCommand(this StDbDriveType driveType, DbConnection conn)
 {
     return(driveType.CreateDbCommand(conn, string.Empty, CommandType.Text, null));
 }
Exemplo n.º 5
0
 /// <summary>
 /// 创建一个新的DBCommand
 /// </summary>
 /// <param name="driveType">数据库驱动类型</param>
 /// <param name="connString">数据库连接字符串</param>
 /// <param name="type">执行方式</param>
 /// <returns></returns>
 public static DbCommand CreateDbCommand(this StDbDriveType driveType, string connString, CommandType type)
 {
     return(driveType.CreateDbCommand(connString, string.Empty, type, null));
 }
Exemplo n.º 6
0
 /// <summary>
 /// 获取DBCommand
 /// </summary>
 /// <param name="driveType">数据库驱动类型</param>
 /// <param name="connString">数据库连接字符串</param>
 /// <param name="text">执行的命令文本</param>
 /// <returns></returns>
 public static DbCommand CreateDbCommand(this StDbDriveType driveType, string connString, string text)
 {
     return(driveType.CreateDbCommand(connString, text, CommandType.Text, null));
 }
Exemplo n.º 7
0
 /// <summary>
 /// 创建一个新的DBCommand
 /// </summary>
 /// <param name="driveType">数据库驱动类型</param>
 /// <param name="connString">数据库连接对象</param>
 /// <param name="text">执行的命令文本</param>
 /// <param name="type">执行方式</param>
 /// <returns></returns>
 public static DbCommand CreateDbCommand(this StDbDriveType driveType, DbConnection conn, string text, CommandType type)
 {
     return(driveType.CreateDbCommand(conn, text, type, null));
 }