• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DbParameter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中DbParameter的典型用法代码示例。如果您正苦于以下问题:C# DbParameter类的具体用法?C# DbParameter怎么用?C# DbParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DbParameter类属于命名空间,在下文中一共展示了DbParameter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ConvertToNativeParameter

        private static IDbDataParameter ConvertToNativeParameter(DbParameter dbParameter, CommandType cmdType)
        {
            IDbDataParameter clone = new OracleParameter() { IsNullable = dbParameter.IsNullable };

            // Remove leading ':' character for stored procedures.
            if (cmdType == CommandType.StoredProcedure)
            {
                string name = parameterRenderer.RenderParameterName(dbParameter);
                if (name.StartsWith(":", StringComparison.Ordinal))
                    name = name.Substring(1, name.Length - 1);

                clone.ParameterName = name;
            }
            else
            {
                clone.ParameterName = parameterRenderer.RenderParameterName(dbParameter);
            }

            if (dbParameter.PassMode == SpArgumentPassMode.DataTableFilledByAdapter)
                ((OracleParameter)clone).OracleDbType = OracleDbType.RefCursor;
            else
                clone.DbType = dbParameter.DbType;

            clone.Direction = dbParameter.Direction;
            clone.Precision = dbParameter.Precision;
            clone.Scale = dbParameter.Scale;
            clone.Size = dbParameter.Size;
            clone.SourceColumn = dbParameter.SourceColumn;
            clone.SourceVersion = dbParameter.SourceVersion;
            clone.Value = dbParameter.Value;

            return clone;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:33,代码来源:OracleCommandBuilder.cs


示例2: DeriveParameters

 public static DbParameter[] DeriveParameters(DbConnection dbConnection, string spName)
 {
     if (dbConnection == null)
     {
         throw new ArgumentNullException("dbConn");
     }
     if (string.IsNullOrEmpty(spName))
     {
         throw new ArgumentNullException("spName");
     }
     DbCommand command = null;
     using (DbConnection connection = (DbConnection) ((ICloneable) dbConnection).Clone())
     {
         command = connection.CreateCommand();
         command.CommandText = spName;
         command.CommandType = CommandType.StoredProcedure;
         connection.Open();
         if (!(command is SqlCommand))
         {
             throw new NotSupportedException();
         }
         SqlCommandBuilder.DeriveParameters((SqlCommand) command);
         connection.Close();
     }
     if ((command.Parameters.Count > 0) && (command.Parameters[0].Direction == ParameterDirection.ReturnValue))
     {
         command.Parameters.RemoveAt(0);
     }
     DbParameter[] array = new DbParameter[command.Parameters.Count];
     command.Parameters.CopyTo(array, 0);
     return array;
 }
开发者ID:nakijun,项目名称:FastDBEngine,代码行数:32,代码来源:DBParametersManager.cs


示例3: updateYouTube

        public void updateYouTube(List<YouTube> youtubes)
        {
            DbParameter[] parameters = new DbParameter[3];
            try
            {
                Ado.ExecuteNonQueryStoredProcedure("DeleteYouTubeUrls", null);
                foreach (YouTube yt in youtubes)
                {
                    parameters[0] = new SqlParameter("@YouTubeLink", yt.YOUTUBELINK);
                    parameters[0].Direction = ParameterDirection.Input;
                    parameters[0].DbType = DbType.String;

                    parameters[1] = new SqlParameter("@NumberOfTimeExecuted", yt.NUMBEROFTIMEEXECUTED);
                    parameters[1].Direction = ParameterDirection.Input;
                    parameters[1].DbType = DbType.Int16;

                    parameters[2] = new SqlParameter("@YouTubeText", yt.YOUTUBETEXT);
                    parameters[2].Direction = ParameterDirection.Input;
                    parameters[2].DbType = DbType.String;

                    Ado.ExecuteNonQueryStoredProcedure("UpdateYouTubeUrls", parameters);
                    //lblError.Visible = true;
                    //lblError.Text = "Updated Successfully";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                parameters = null;
            }
        }
开发者ID:nitinchaurasia09,项目名称:AntaraApplication,代码行数:34,代码来源:YouTube.cs


示例4: RenderInsert

        /// <summary>
        /// Renders INSERT statement and code that retrieves the new ID.
        /// </summary>
        /// <param name="insert">INSERT statement that is being rendered.</param>
        /// <param name="nextSequence">Ignored. SQL Server CE doesn't use sequences.</param>
        /// <param name="dbms">Target DBMS.</param>
        /// <param name="output">StringBuilder to which the SQL code is appended.</param>
        /// <param name="parameters">SQL parameter collection to which the object's and its children's
        /// parameters are added. After the rendering is done the collection contains all parameters with unique names.</param>
        /// <returns><b>null</b> because automatically generated ID must be fetched via SELECT after INSERT.</returns>
        public DbParameter RenderInsert(InsertStatement insert, DbParameter nextSequence, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            // Renders INSERT statements for DBMSs that support an auto-identity fields.
            // Auto-id field may or may not be in the column-value list.
            // If auto-incremented field is in the column-value list it will be skipped.
            // Table may have only one auto-identity field.
            // Method expects that all errors have been identified and processed in the caller.
            // Renders all fields except auto-id field; thus -1 if auto-id is contained in the column-value list.
            int numberOfFieldsToRender = GetTotalNumberOfFieldsToRender(insert);

            AppendInsertIntoTableName(insert, dbms, output);
            if (numberOfFieldsToRender > 0)
            {
                AppendBracketsWithAllFieldsExceptAutoId(insert, dbms, output, numberOfFieldsToRender);
                AppendValuesForAllFieldsExceptAutoId(insert, dbms, output, parameters, numberOfFieldsToRender);
            }
            else
            {
                AppendDefaultValuesExpression(output);
            }

            // Auto ID must be fetched via SELECT after INSERT.
            DbParameter autoId = null;
            return autoId;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:35,代码来源:SqlServerCeInserter.cs


示例5: CloneParameters

 public static DbParameter[] CloneParameters(DbParameter[] dbParameters)
 {
     int length = dbParameters.Length;
     DbParameter[] parameterArray = new DbParameter[length];
     for (int i = 0; i < length; i++)
     {
         parameterArray[i] = (DbParameter)((ICloneable)dbParameters[i]).Clone();
     }
     return parameterArray;
 }
开发者ID:nakijun,项目名称:FastDBEngine,代码行数:10,代码来源:ProcParametersDeriver.cs


示例6: Add

 /// <summary>
 /// 添加SqlCommand 的参数
 /// </summary>
 /// <param name="CmdParameters">SqlCommand 的参数</param>
 public void Add(DbParameter[] CmdParameters)
 {
     foreach (MySqlParameter parameter in CmdParameters)
     {
         if ((parameter.Direction == ParameterDirection.InputOutput) & Convert.IsDBNull(RuntimeHelpers.GetObjectValue(parameter.Value)))
         {
             parameter.Value = DBNull.Value;
         }
         this.Cmd.Parameters.Add(parameter);
     }
 }
开发者ID:kuibono,项目名称:Voodoo-1,代码行数:15,代码来源:MySqlHelper.cs


示例7: UpdateImportDate

        public void UpdateImportDate(long id, DateTime importTime)
        {
            string sql = string.Format("update {0} set {1} = @{1} where {2} = @{2}", T_TableName,
                C_ImportDate, C_Id);

            DbParameter[] parameters = new DbParameter[]{
                new MySqlParameter(string.Format("@{0}", C_ImportDate), importTime),
                new MySqlParameter(string.Format("@{0}", C_Id), id)
            };

            this.ExecuteNonQuery(sql, parameters);
        }
开发者ID:GemHu,项目名称:ExportManager,代码行数:12,代码来源:ImportRecordTable.cs


示例8: ArchiveMailsOlderThan

        public void ArchiveMailsOlderThan(DateTime archiveDate)
        {
            string insertIntoArchive = "insert into " + archiveTableName + " SELECT * from " + tableName + " where " + sentColumn + "<@archiveDate";
            DbParameter[] parameters = new DbParameter[] {
                new DbParameter("@archiveDate", SqlDbType.DateTime, archiveDate)
            };
            dbTemplate.Update(insertIntoArchive, parameters);

            string deleteMails = "delete from " + tableName + " where " + sentColumn + "<@archiveDate";
            parameters = new DbParameter[] {
                new DbParameter("@archiveDate", SqlDbType.DateTime, archiveDate)
            };
            dbTemplate.Update(deleteMails, parameters);
        }
开发者ID:greenwall,项目名称:QMail,代码行数:14,代码来源:MailDao.cs


示例9: ExecuteScalar

    /// <summary>
    ///     A DbConnection extension method that executes the scalar operation.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="cmdText">The command text.</param>
    /// <param name="parameters">Options for controlling the operation.</param>
    /// <param name="commandType">Type of the command.</param>
    /// <param name="transaction">The transaction.</param>
    /// <returns>An object.</returns>
    public static object ExecuteScalar(this DbConnection @this, string cmdText, DbParameter[] parameters, CommandType commandType, DbTransaction transaction)
    {
        using (DbCommand command = @this.CreateCommand())
        {
            command.CommandText = cmdText;
            command.CommandType = commandType;
            command.Transaction = transaction;

            if (parameters != null)
            {
                command.Parameters.AddRange(parameters);
            }

            return command.ExecuteScalar();
        }
    }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:25,代码来源:DbConnection.ExecuteScalar.cs


示例10: RenderInsert

        /// <summary>
        /// Renders INSERT statement and code that retrieves the new ID.
        /// </summary>
        /// <param name="insert">INSERT statement that is being rendered.</param>
        /// <param name="nextSequence">Ignored. SQL Server doesn't use sequences.</param>
        /// <param name="dbms">Target DBMS. Different auto-id retrieval for SQL 7.0 then in newer versions.</param>
        /// <param name="output">StringBuilder to which the SQL code is appended.</param>
        /// <param name="parameters">SQL parameter collection to which the object's and its children's
        /// parameters are added. After the rendering is done the collection contains all parameters with unique names.</param>
        /// <returns>Parameter that contains the ID of the inserted row. <b>null</b> if auto-id field is not used.</returns>
        public DbParameter RenderInsert(InsertStatement insert, DbParameter nextSequence, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            // Renders INSERT statements for DBMSs that support an auto-identity fields.
            // Auto-id field may or may not be in the column-value list.
            // If auto-incremented field is in the column-value list it will be skipped.
            // Table may have only one auto-identity field.
            // Method expects that all errors have been identified and processed in the caller.
            // Renders all fields except auto-id field; thus -1 if auto-id is contained in the column-value list.
            int numberOfFieldsToRender = GetTotalNumberOfFieldsToRender(insert);

            AppendInsertIntoTableName(insert, dbms, output);
            if (numberOfFieldsToRender > 0)
            {
                AppendBracketsWithAllFieldsExceptAutoId(insert, dbms, output, numberOfFieldsToRender);
                AppendValuesForAllFieldsExceptAutoId(insert, dbms, output, parameters, numberOfFieldsToRender);
            }
            else
            {
                AppendDefaultValuesExpression(output);
            }

            DbParameter autoId = null;
            if (HasAutoIdField(insert.Table))
            {
                autoId = new DbParameter("___newAutoIdentity___", DbType.Int32) { Direction = ParameterDirection.Output };
                if (dbms == DbmsType.SqlServer_7)
                {
                    // @@IDENTITY
                    output.Append(" ; set ");
                    autoId.Render(dbms, output, parameters);
                    output.Append(" = @@IDENTITY");
                }
                else
                {
                    // scope_identity()
                    output.Append(" ; set ");
                    autoId.Render(dbms, output, parameters);
                    output.Append(" = scope_identity()");
                }

                // BatchQuery (if ever implemented) reads this value to assign new ID value to InsertStatement.RetrievedData property.
                //insert.NewIdOutputParameterIndexAfterRenderCompleted = parameters.Count - 1;
            }

            // Return auto-id DB parameter. Callers require it to retrieve the new ID value.
            return autoId;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:57,代码来源:SqlServerInserter.cs


示例11: ConvertToNativeParameter

        private static IDbDataParameter ConvertToNativeParameter(DbParameter dbParameter)
        {
            IDbDataParameter clone = new OleDbParameter();
            ((OleDbParameter)clone).IsNullable = dbParameter.IsNullable;
            clone.ParameterName = parameterRenderer.RenderParameterName(dbParameter);

            clone.DbType = dbParameter.DbType;
            clone.Direction = dbParameter.Direction;
            clone.Precision = dbParameter.Precision;
            clone.Scale = dbParameter.Scale;
            clone.Size = dbParameter.Size;
            clone.SourceColumn = dbParameter.SourceColumn;
            clone.SourceVersion = dbParameter.SourceVersion;
            clone.Value = dbParameter.Value;

            return clone;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:17,代码来源:OleDbCommandBuilder.cs


示例12: ExecuteExpandoObjects

    /// <summary>
    ///     Enumerates execute expando objects in this collection.
    /// </summary>
    /// <param name="this">The @this to act on.</param>
    /// <param name="cmdText">The command text.</param>
    /// <param name="parameters">Options for controlling the operation.</param>
    /// <param name="commandType">Type of the command.</param>
    /// <param name="transaction">The transaction.</param>
    /// <returns>
    ///     An enumerator that allows foreach to be used to process execute expando objects in this collection.
    /// </returns>
    public static IEnumerable<dynamic> ExecuteExpandoObjects(this DbConnection @this, string cmdText, DbParameter[] parameters, CommandType commandType, DbTransaction transaction)
    {
        using (DbCommand command = @this.CreateCommand())
        {
            command.CommandText = cmdText;
            command.CommandType = commandType;
            command.Transaction = transaction;

            if (parameters != null)
            {
                command.Parameters.AddRange(parameters);
            }

            using (IDataReader reader = command.ExecuteReader())
            {
                return reader.ToExpandoObjects();
            }
        }
    }
开发者ID:ChuangYang,项目名称:Z.ExtensionMethods,代码行数:30,代码来源:DbConnection.ExecuteExpandoObjects.cs


示例13: deleteAnswerByAnswerId

 public void deleteAnswerByAnswerId(Guid guid)
 {
     DbParameter[] parameters = new DbParameter[1];
     try
     {
         parameters[0] = new SqlParameter("@guid", guid);
         parameters[0].Direction = ParameterDirection.Input;
         parameters[0].DbType = DbType.Guid;
         Ado.ExecuteNonQueryStoredProcedure("sp_DeleteAnswer", parameters);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         parameters = null;
     }
 }
开发者ID:nitinchaurasia09,项目名称:AntaraApplication,代码行数:19,代码来源:Answer.cs


示例14: AttachParameters

        private static void AttachParameters(DbCommand command, DbParameter[] commandParameters)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (commandParameters != null)
            {
                foreach (DbParameter p in commandParameters)
                {
                    if (p != null)
                    {
                        if ((p.Direction == ParameterDirection.InputOutput ||
                            p.Direction == ParameterDirection.Input) &&
                            (p.Value == null))
                        {
                            p.Value = DBNull.Value;
                        }

                        command.Parameters.Add(p);
                    }
                }
            }
        }
开发者ID:freemsly,项目名称:cloudscribe,代码行数:21,代码来源:AdoHelper.cs


示例15: RenderInsert

        public DbParameter RenderInsert(InsertStatement insert, DbParameter nextSequence, DbmsType dbms, StringBuilder output, DbParameterCollection parameters)
        {
            // Auto ID: sequence if it is defined, or NULL and hope that a trigger will take care of auto ID field.
            IDbColumn autoIdField = GetAutoIdField(insert.Table);
            bool hasAutoIdField = (autoIdField != null);
            bool autoIdIsAlreadyInInsertList = IsAutoIdFieldInColumnValueList(insert);
            bool mustAppendAutoIdField = (hasAutoIdField && !autoIdIsAlreadyInInsertList);

            AppendInsertIntoTableName(insert, dbms, output);
            AppendColumnListInBrackets(insert, dbms, output, autoIdField, mustAppendAutoIdField);
            RenderValueListAndNextSequenceExpression(insert, dbms, output, parameters, autoIdField, mustAppendAutoIdField);

            if (autoIdField != null && nextSequence != null)
            {
                // RETURNING id
                output.Append(" RETURNING ");
                autoIdField.RenderColumnName(dbms, output);
                output.Append(" INTO ");
                nextSequence.Render(dbms, output, parameters);
            }

            return nextSequence;
        }
开发者ID:lordfist,项目名称:FistCore.Lib,代码行数:23,代码来源:OracleInserter.cs


示例16: getAllYouTubeLink

 public DataTable getAllYouTubeLink()
 {
     DbParameter[] parameters = new DbParameter[1];
     //parameters = null;
     DataTable dtUser = new DataTable();
     try
     {
         parameters[0] = new SqlParameter("@guid", null);
         parameters[0].Direction = ParameterDirection.Input;
         parameters[0].DbType = DbType.Guid;
         dtUser = Ado.ExecuteStoredProcedure("sp_GetAllYTlinks", parameters);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         parameters = null;
         dtUser.Dispose();
     }
     return dtUser;
 }
开发者ID:nitinchaurasia09,项目名称:AntaraApplication,代码行数:23,代码来源:YouTube.cs


示例17: PrepareCommand

        private static void PrepareCommand(
            DbCommand command,
            DbConnection connection,
            DbTransaction transaction,
            CommandType commandType,
            string commandText,
            DbParameter[] commandParameters)
        {
            if (command == null) throw new ArgumentNullException("command");
            if (string.IsNullOrEmpty(commandText)) throw new ArgumentNullException("commandText");

            command.CommandType = commandType;
            command.CommandText = commandText;
            command.Connection = connection;

            if (transaction != null)
            {
                if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
                command.Transaction = transaction;
            }

            if (commandParameters != null) { AttachParameters(command, commandParameters); }
        }
开发者ID:freemsly,项目名称:cloudscribe,代码行数:23,代码来源:AdoHelper.cs


示例18: getAllAnswer

 public DataTable getAllAnswer()
 {
     DbParameter[] parameters = new DbParameter[1];
     //parameters = null;
     DataTable dtAnswer = new DataTable();
     try
     {
         parameters[0] = new SqlParameter("@blogId", BLOGID);
         parameters[0].Direction = ParameterDirection.Input;
         parameters[0].DbType = DbType.Guid;
         dtAnswer = Ado.ExecuteStoredProcedure("sp_GetAllAnswer", parameters);
     }
     catch (Exception ex)
     {
         throw ex;
     }
     finally
     {
         parameters = null;
         dtAnswer.Dispose();
     }
     return dtAnswer;
 }
开发者ID:nitinchaurasia09,项目名称:AntaraApplication,代码行数:23,代码来源:Answer.cs


示例19: ApplyParameterInfo

 protected override void ApplyParameterInfo(DbParameter parameter, DataRow row,
   StatementType statementType, bool whereClause)
 {
   ((MySqlParameter)parameter).MySqlDbType = (MySqlDbType)row["ProviderType"];
 }
开发者ID:RoxyLalonde,项目名称:Phoenix-Realms,代码行数:5,代码来源:CommandBuilder.cs


示例20: PrepareCommand

        private void PrepareCommand(DbCommand cmd, DbConnection conn, SqlTransaction trans, string cmdText, DbParameter[] cmdParms)
        {
            if (conn.State != ConnectionState.Open)
                conn.Open();
            cmd.Connection = conn;
            cmd.CommandText = cmdText;
            if (trans != null)
                cmd.Transaction = trans;
            cmd.CommandType = CommandType.Text;//cmdType;
            if (cmdParms != null)
            {

                foreach (DbParameter parameter in cmdParms)
                {
                    if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
                        (parameter.Value == null))
                    {
                        parameter.Value = DBNull.Value;
                    }
                    cmd.Parameters.Add(parameter);
                }
            }
        }
开发者ID:SaintLoong,项目名称:PD,代码行数:23,代码来源:DataTransaction.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DbParameterCollection类代码示例发布时间:2022-05-24
下一篇:
C# DbModelBuilder类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap