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


C# DBConnection.ExecuteNonQueryCommand方法代码示例

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


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

示例1: Execute

        /// <summary>
        /// Executes this command against the specified database connection and returns the auto-increment value of the inserted row, or null if it is not an
        /// auto-increment table.
        /// </summary>
        public object Execute( DBConnection cn )
        {
            var cmd = cn.DatabaseInfo.CreateCommand();
            cmd.CommandText = "INSERT INTO " + table;
            if( columnModifications.Count == 0 )
                cmd.CommandText += " DEFAULT VALUES";
            else {
                cmd.CommandText += "( ";
                foreach( var columnMod in columnModifications )
                    cmd.CommandText += columnMod.ColumnName + ", ";
                cmd.CommandText = cmd.CommandText.Substring( 0, cmd.CommandText.Length - 2 );
                cmd.CommandText += " ) VALUES( ";
                foreach( var columnMod in columnModifications ) {
                    var parameter = columnMod.GetParameter();
                    cmd.CommandText += parameter.GetNameForCommandText( cn.DatabaseInfo ) + ", ";
                    cmd.Parameters.Add( parameter.GetAdoDotNetParameter( cn.DatabaseInfo ) );
                }
                cmd.CommandText = cmd.CommandText.Substring( 0, cmd.CommandText.Length - 2 );
                cmd.CommandText += " )";
            }
            cn.ExecuteNonQueryCommand( cmd );

            if( !cn.DatabaseInfo.LastAutoIncrementValueExpression.Any() )
                return null;
            var autoIncrementRetriever = cn.DatabaseInfo.CreateCommand();
            autoIncrementRetriever.CommandText = "SELECT {0}".FormatWith( cn.DatabaseInfo.LastAutoIncrementValueExpression );
            var autoIncrementValue = cn.ExecuteScalarCommand( autoIncrementRetriever );
            return autoIncrementValue != DBNull.Value ? autoIncrementValue : null;
        }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:33,代码来源:InlineInsert.cs

示例2: Execute

 /// <summary>
 /// Executes this command against the specified database connection and returns the number of rows affected.
 /// </summary>
 public int Execute( DBConnection cn )
 {
     if( conditions.Count == 0 )
         throw new ApplicationException( "Executing an inline delete command with no parameters in the where clause is not allowed." );
     var command = cn.DatabaseInfo.CreateCommand();
     command.CommandText = "DELETE FROM " + tableName + " WHERE ";
     var paramNumber = 0;
     foreach( var condition in conditions ) {
         condition.AddToCommand( command, cn.DatabaseInfo, InlineUpdate.GetParamNameFromNumber( paramNumber++ ) );
         command.CommandText += " AND ";
     }
     command.CommandText = command.CommandText.Remove( command.CommandText.Length - 5 );
     return cn.ExecuteNonQueryCommand( command );
 }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:17,代码来源:InlineDelete.cs

示例3: Execute

        /// <summary>
        /// Executes this command against the specified database connection and returns the number of rows affected.
        /// </summary>
        public int Execute( DBConnection cn )
        {
            if( columnModifications.Count == 0 )
                return 0;
            if( conditions.Count == 0 )
                throw new ApplicationException( "Executing an inline update command with no parameters in the where clause is not allowed." );

            var command = cn.DatabaseInfo.CreateCommand();
            command.CommandText = "UPDATE " + tableName + " SET ";
            var paramNumber = 0;
            foreach( var columnMod in columnModifications ) {
                var parameter = columnMod.GetParameter( name: GetParamNameFromNumber( paramNumber++ ) );
                command.CommandText += columnMod.ColumnName + " = " + parameter.GetNameForCommandText( cn.DatabaseInfo ) + ", ";
                command.Parameters.Add( parameter.GetAdoDotNetParameter( cn.DatabaseInfo ) );
            }
            command.CommandText = command.CommandText.Remove( command.CommandText.Length - 2 );
            command.CommandText += " WHERE ";
            foreach( var condition in conditions ) {
                condition.AddToCommand( command, cn.DatabaseInfo, GetParamNameFromNumber( paramNumber++ ) );
                command.CommandText += " AND ";
            }
            command.CommandText = command.CommandText.Remove( command.CommandText.Length - 5 );
            return cn.ExecuteNonQueryCommand( command );
        }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:27,代码来源:InlineUpdate.cs

示例4: executeLongRunningCommand

        private void executeLongRunningCommand( DBConnection cn, string commandText )
        {
            var command = cn.DatabaseInfo.CreateCommand();
            command.CommandTimeout = 0; // This means the command can take as much time as it needs.
            command.CommandText = commandText;

            // NOTE: Not sure if this is the right execute method to use.
            cn.ExecuteNonQueryCommand( command );
        }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:9,代码来源:Oracle.cs

示例5: ExecuteNonQuery

 /// <summary>
 /// Executes this sproc against the specified database connection and returns the number of rows affected.
 /// </summary>
 public int ExecuteNonQuery( DBConnection cn )
 {
     var cmd = cn.DatabaseInfo.CreateCommand();
     setupDbCommand( cmd, cn.DatabaseInfo );
     return cn.ExecuteNonQueryCommand( cmd );
 }
开发者ID:william-gross,项目名称:enterprise-web-library,代码行数:9,代码来源:SprocExecution.cs


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