  Let $\mathbb{F}_q$ be the finite field of $q$ elements and $a_1,a_2, \ldots,
a_k, b\in \mathbb{F}_q$. We investigate $N_{\mathbb{F}_q}(a_1, a_2,
\ldots,a_k;b)$, the number of ordered solutions $(x_1, x_2,
\ldots,x_k)\in\mathbb{F}_q^k$ of the linear equation $$
a_1x_1+a_2x_2+\cdots+a_kx_k=b$$ with all $x_i$ distinct. We obtain an explicit
formula for $N_{\mathbb{F}_q}(a_1,a_2, \ldots, a_k;b)$ involving combinatorial
numbers depending on $a_i$'s. In particular, we obtain closed formulas for two
special cases. One is that $a_i, 1\leq i\leq k$ take at most three distinct
values and the other is that $\sum_{i=1}^ka_i=0$ and $\sum_{i\in I}a_i\neq 0$
for any $I\subsetneq [k]$.
  The same technique works when $\mathbb{F}_q$ is replaced by $\mathbb{Z}_n$,
the ring of integers modulo $n$. In particular, we give a new proof for the
main result given by Bibak, Kapron and Srinivasan, which generalizes a theorem
of Sch\"{o}nemann via a graph theoretic method.
