首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SQLHelper类- ExecuteNonQuery代码修改

SQLHelper类- ExecuteNonQuery代码修改
EN

Stack Overflow用户
提问于 2009-06-26 20:09:56
回答 1查看 1.6K关注 0票数 1

我正在浏览SQLHelper类V2中的代码,并注意到以下内容

代码语言:javascript
复制
    public static int ExecuteNonQuery(SqlTransaction transaction, CommandType commandType, string commandText, params SqlParameter[] commandParameters)
    {
        if( transaction == null ) throw new ArgumentNullException( "transaction" );
        if( transaction != null && transaction.Connection == null ) throw new ArgumentException( "The transaction was rollbacked or commited, please provide an open transaction.", "transaction" );

        // Create a command and prepare it for execution
        SqlCommand cmd = new SqlCommand();
        bool mustCloseConnection = false;
        PrepareCommand(cmd, transaction.Connection, transaction, commandType, commandText, commandParameters, out mustCloseConnection );

        // Finally, execute the command
        int retval = cmd.ExecuteNonQuery();

        // Detach the SqlParameters from the command object, so they can be used again
        cmd.Parameters.Clear();
        return retval;
    }

命令不在“使用Bolck”范围内有什么原因吗?我在代码的其他地方看到了“Using Block”的用法。

EN

回答 1

Stack Overflow用户

发布于 2009-06-26 20:25:57

我的猜测是,这是因为该命令在整个函数范围内都在使用,所以它只会添加额外的代码。不同的开发人员喜欢不同的实现。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1051034

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档