我正在浏览SQLHelper类V2中的代码,并注意到以下内容
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”的用法。
发布于 2009-06-26 20:25:57
我的猜测是,这是因为该命令在整个函数范围内都在使用,所以它只会添加额外的代码。不同的开发人员喜欢不同的实现。
https://stackoverflow.com/questions/1051034
复制相似问题