I presume that your variety $X$ is smooth.

Consider the additive map $\mathrm d\log \colon \mathscr O_X^*\to \Omega^1_X$ that sends $f$ to $\mathrm df/f$. It induces a map $c_1$ in cohomology from $H^1(X,\mathscr O_X^*)$
to $H^1(X,\Omega^1_X)$ — a coherent avatar of the first Chern class.
By Hodge Theory, $H^1(X,\Omega^1_X)$ is a subspace of $H^2(X,\mathbf C)$ and the two notions
of first Chern class coincide.

A line bundle $\mathscr L$ has a connection if and only if its first Chern class $c_1(\mathscr L)\in H^1(X,\Omega^1_X)$ vanishes. The proof is straightforward: take an open cover $(U_i)$ of $X$, an invertible section $s_i$ of $\mathscr L$ on $U_i$ and the associated cocycle $(f_{ij})$ representing your line bundle in $H^1(X,\mathscr O_X^*)$. A connection $\nabla$ maps $s_i$ to $s_i\otimes\omega_i$, for some 1-form $\omega_i\in H^0(U_i,\Omega^1_X)$. The condition that these $s_i\otimes\omega_i$ come from a global connection on $X$ is exactly the vanishing of $c_1(\mathscr L)$.

It is a non-trivial fact that if $\mathscr L$ has an algebraic connection, then it is automatically flat. Torsten Ekedahl gave an algebraic proof on this thread of MO
(Ekedahl also observes that $p$th power of line bundles in characteristic $p$ have an integrable connection), but an analytic proof seems easy. The algebraic connexion $\nabla$ gives rise to a connexion $\nabla+\bar\partial$ on the associated holomorphic line bundle. One checks that the curvature of this connection is a $(2,0)$-form, while it should be a $(1,1)$-form. Consequently, it vanishes.

When non empty, the set of flat connections on a vector bundle $\mathscr E$ is an affine space under $H^0(X,\Omega^1_X\otimes\mathscr E\mathit{nd}(\mathscr E))$, a finite dimensional vector space. In our case, $\mathscr L$ is a line bundle, hence $\mathscr E\mathit{nd}(\mathscr L)$ is the trivial line bundle so that we get $H^0(X,\Omega^1_X)$.

NB. Following the comment of Ben McKay, I edited the last paragraph.