This is an excerpt from my textbook: Consider the general differential containing two variables, where $f = f(x,y)$, $$ d f=A(x, y) d x+B(x, y) d y $$ We see that $$ \frac{\partial f}{\partial x}=A(x, y), \quad \frac{\partial f}{\partial y}=B(x, y) $$ and, using the property $f_{x y}=f_{y x},$ we therefore require $$ \frac{\partial A}{\partial y}=\frac{\partial B}{\partial x} $$ This is in fact both a necessary and a sufficient condition for the differential to be exact.
I see why this is a necessary condition, but why is it a sufficient condition?
Assume that $A,B $ and its first order partial derivatives are continuous on a simply connected open set $D$.
Given $\frac{\partial A}{\partial y}=\frac{\partial B}{\partial x}$, if there exists a function $h(x,y)$ such that $d(h(x,y))=Adx+Bdy\tag{A}$, then we are done.
Let's denote $h(x,y)$ by $h$.
Consider, $\frac{\partial h }{\partial x}=A$ and $\frac{\partial h }{\partial y}=B$. Let $(a,b)$ and $(x,y)\in D$
From $\frac{\partial h }{\partial x}=A$, we have : $h=\int_{x=a}^{x} A\partial x+g(y)\tag{1}$
Therefore, by $\frac{\partial h }{\partial y}=B$, we get $\frac{\partial }{\partial y}(\int_{x=a}^{x} A\partial x)+g'(y)=B\implies \int_{x=a}^{x}\frac{\partial }{\partial y}A \partial x+g'(y)=B\implies g'(y)=B-\frac{\partial }{\partial x}(\int_{x=a}^{x}B\partial x)=B-B(x,y)+B(a,y)=B(a,y)\tag{2}$
So, we have now shown that $g'(y)$ is free of $x$, that is we can find $g(y)$ from $(2)$ using FTC. $g(y)=g(b) +\int_{y=b}^{y} g'(y) dy=g(b) +\int_{y=b}^{y} B(a,y) dy$. So now $g(y)$ is known.
We'll put this $g(y)$ into $(1)$ and we'll have known $h$. And clearly the way $h$ was constructed implies that $(A)$ is satisfied by $h$.