예제 #1
0
        /// <summary>
        /// 根据配置文件中所配置的数据库类型
        /// 来创建相应数据库的参数对象
        /// </summary>
        /// <returns></returns>
        public static DbParameter CreateDbParameter(string paramName, object value, DbType dbType)
        {
            DbParameter param = DbParameterExtension.CreateDbParameter();

            param.DbType        = dbType;
            param.ParameterName = paramName;
            param.Value         = value;
            return(param);
        }
예제 #2
0
 /// <summary>
 /// 为即将执行准备一个命令
 /// </summary>
 /// <param name="conn">SqlConnection对象</param>
 /// <param name="cmd">SqlCommand对象</param>
 /// <param name="isOpenTrans">DbTransaction对象</param>
 /// <param name="cmdType">执行命令的类型(存储过程或T-SQL,等等)</param>
 /// <param name="strSql">存储过程名称或者T-SQL命令行, e.g. Select * from Products</param>
 /// <param name="dbParameter">执行命令所需的sql语句对应参数</param>
 private void PrepareCommand(DbConnection conn, IDbCommand cmd, DbTransaction isOpenTrans, CommandType cmdType, string strSql, params DbParameter[] dbParameter)
 {
     if (conn.State != ConnectionState.Open)
     {
         conn.Open();
     }
     cmd.Connection  = conn;
     cmd.CommandText = strSql; // DbParameters.ToDbSql(cmdText);
     if (isOpenTrans != null)
     {
         cmd.Transaction = isOpenTrans;
     }
     cmd.CommandType = cmdType;
     if (dbParameter != null)
     {
         dbParameter = DbParameterExtension.ToDbParameter(dbParameter);
         foreach (var parameter in dbParameter)
         {
             cmd.Parameters.Add(parameter);
         }
     }
 }