当前位置: 首页>>代码示例>>C#>>正文


C# Database.DiscoverParameters方法代码示例

本文整理汇总了C#中Microsoft.Practices.EnterpriseLibrary.Data.Database.DiscoverParameters方法的典型用法代码示例。如果您正苦于以下问题:C# Database.DiscoverParameters方法的具体用法?C# Database.DiscoverParameters怎么用?C# Database.DiscoverParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Practices.EnterpriseLibrary.Data.Database的用法示例。


在下文中一共展示了Database.DiscoverParameters方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DiscoverParameters

 /// <summary>
 /// 找出 <paramref name="command"/> 脚本中定义的参数列表,并将参数列表加入其属性 Parameters 中。
 /// </summary>
 /// <param name="database">表示一个 <see cref="Microsoft.Practices.EnterpriseLibrary.Data.Database"/> 对象。</param>
 /// <param name="command">用于查找参数列表的 <see cref="DbCommand"/> 对象。</param>
 public static void DiscoverParameters(Database database, DbCommand command)
 {
     if (command.CommandType == CommandType.StoredProcedure)
     {
         database.DiscoverParameters(command);
         return;
     }
     Check.NotEmpty(command.CommandText, "command.CommandText");
     var parser = NDF.Data.Common.DbProviderFactoryExtensions.GetScriptParameterParser(database.DbProviderFactory);
     string[] parameterNames = parser.GetParameterNames(command.CommandText);
     foreach (var paremeterName in parameterNames)
     {
         DbParameter parameter = CreateParameter(database, paremeterName);
         command.Parameters.Add(parameter);
     }
 }
开发者ID:kylin589,项目名称:NDF.Infrastructure,代码行数:21,代码来源:DatabaseExtensions.DiscoverParameters.cs

示例2: SetParameters

        /// <summary>
        /// <para>
        /// Populates the parameter collection for a command wrapper from the cache 
        /// or performs a round-trip to the database to query the parameters.
        /// </para>
        /// </summary>
        /// <param name="command">
        /// <para>The command to add the parameters.</para>
        /// </param>
        /// <param name="database">
        /// <para>The database to use to set the parameters.</para>
        /// </param>
        public void SetParameters(DbCommand command, Database database)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (database == null) throw new ArgumentNullException("database");

            if (AlreadyCached(command, database))
            {
                AddParametersFromCache(command, database);
            }
            else
            {
                database.DiscoverParameters(command);
                IDataParameter[] copyOfParameters = CreateParameterCopy(command);

                this.cache.AddParameterSetToCache(database.ConnectionString, command, copyOfParameters);
            }
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:29,代码来源:ParameterCache.cs

示例3: PrepCommand

        private static DbCommand PrepCommand(Database db, string procName, params object[] parameterVals)
        {
            DbCommand dbCommand = db.GetStoredProcCommand(procName);
            dbCommand.CommandTimeout = 180;
            db.DiscoverParameters(dbCommand);

            int numVals = parameterVals.Length;
            /// Start at 1; skip 0 which is RETURN_VALUE.
            for (int i = 1; i < dbCommand.Parameters.Count; i++)
            {
                /// parameterVals should have same # elements, but index is offset by 1 compared to dbCommand.Parameters.
                int valIndex = i - 1;
                object value = valIndex < numVals ? parameterVals[valIndex] : null;
                db.SetParameterValue(dbCommand, dbCommand.Parameters[i].ParameterName, value);
            }

            return dbCommand;
        }
开发者ID:wonkim00,项目名称:Core,代码行数:18,代码来源:Data.cs

示例4: CreateSQLCommand

 public DbCommand CreateSQLCommand(Database objDB, string SPName)
 {
     DbCommand objCommand = null;
     try
     {
         if (SPName.Trim().Length > 0)
         {
             //Create Command object
             objCommand = objDB.GetStoredProcCommand(SPName);
             //Derive Parameters of SP
             objDB.DiscoverParameters(objCommand);
             // Assign the provided source columns to these parameters based on parameter order
             for (int index = 0; index < objCommand.Parameters.Count; index++)
                 objCommand.Parameters[index].SourceColumn = objCommand.Parameters[index].ParameterName.Substring(1, objCommand.Parameters[index].ParameterName.Length - 1);
         }
         else
         {
             throw new Exception("Stored Procedure Name cannot be empty.");
         }
     }
     catch (Exception ex)
     {
         ExceptionManager.Publish(ex);
         throw ex;
     }
     return objCommand;
 }
开发者ID:pratikmoda,项目名称:GreyMediaHouse,代码行数:27,代码来源:BL_Common.cs


注:本文中的Microsoft.Practices.EnterpriseLibrary.Data.Database.DiscoverParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。