TITLE: Criterion for a subvariety to be affine?
QUESTION [5 upvotes]: Say $X$ is an algebraic variety and $U\subset X$ is open.  Consider the natural map $U\rightarrow \operatorname{Spm}(\mathcal{O}_X(U))$ given by sending a point of $U$ to the ideal of sections over $U$ that vanish on that point.  $U$ is affine if and only if this map is an isomorphism of varieties.
Is it enough to know $U$ is a bijection of sets? (It seems to me it should be! The ring of global sections on $\operatorname{Spm}(\mathcal{O}_X(U))$ is already $\mathcal{O}_X(U)$ right?  So the rings already match!  We just need to check that the sets match... what am I missing?)
EDIT (in response to comments by QiL):
First, let me add the assumption that $\mathcal{O}_X(U)$ is finitely generated as a $k$-algebra, so that $\operatorname{Spm}(\mathcal{O}_X(U))$ is an affine variety.
Second, let me state the definition of algebraic variety I'm working with: a separated prevariety.  A prevariety is a quasicompact topological space with a sheaf of $k$-valued functions (for $k$ some algebraically closed field) such that every point is contained in an open set such that the restriction of the sheaf to that set makes it isomorphic (as a ringed space) to an affine variety.  An affine variety is the $\operatorname{Spm}$ of a finitely generated reduced $k$-algebra.

REPLY [2 votes]: This is not a complete answer. 
First you should probably work with Spec rather that Spm because $O_X(U)$ in general is not a finitely generated algebra and you can't call Spm$(O_X(U))$ an algebraic variety. 
Working with Spec, there is a lemma in Stack project (23.14.4 in my version) which says that if $U$ is quasi-affine, then $U\to \mathrm{Spec}(O_X(U))$ is always an open immersion (and the converse is quasi-true). So under your hypothesis it is an isomorphism and $U$ is affine.