The electronic structure of $R{\mathrm{Ni}}_{2}{\mathrm{B}}_{2}\mathrm{C}$ $(R=\mathrm{Y},$ $\mathrm{L}\mathrm{a},\phantom{\rule{0ex}{0ex}}\mathrm{P}\mathrm{r}--\mathrm{T}\mathrm{m},\phantom{\rule{0ex}{0ex}}\mathrm{L}\mathrm{u})$ is systematically studied using density functional theory (DFT). The partially occupied $4f$ states are assumed to be localized for both the light and heavy rare earths $(R=\mathrm{Pr},$ $\mathrm{N}\mathrm{d},\phantom{\rule{0ex}{0ex}}\mathrm{S}\mathrm{m},\phantom{\rule{0ex}{0ex}}\mathrm{T}\mathrm{b},\phantom{\rule{0ex}{0ex}}\mathrm{D}\mathrm{y},\phantom{\rule{0ex}{0ex}}\mathrm{H}\mathrm{o},\phantom{\rule{0ex}{0ex}}\mathrm{E}\mathrm{r},\phantom{\rule{0ex}{0ex}}\mathrm{T}\mathrm{m})$ and treated in the ``open core approximation.'' In the case of Gd (Lu) the $4f$ states are treated both as itinerant and as part of the atomiclike core states. The calculations of the electronic density of states (DOS) show that the Fermi energy ${E}_{f}$ is located in a pronounced peak for $R=\mathrm{Y},$ Dy, Ho, Er, Tm, and Lu. This peak starts to be broadened for $R=\mathrm{Tb},$ Gd, and Sm and finally disappears for $R=\mathrm{Pr},$ Nd. This reduction is large enough to explain the depression of superconductivity to below 3 K in the light rare-earth borocarbides. Additional calculations of the Hopfield parameters support this conclusion. The charge density distribution and general features of the bonding mechanism are discussed. The relations between the DOS in the vicinity of ${E}_{f}$ and the lattice parameters $a,c$ and the free internal structural parameter ${z}_{B}$ of boron are studied using the DFT total energy and force calculations. The total energy is very sensitive to the $c/a$ ratio and the optimum DFT values of $c/a$ and ${z}_{B}$ are close to those observed in the experiment. The electric field gradients (EFG) on the Gd- $({\mathrm{GdNi}}_{2}{\mathrm{B}}_{2}\mathrm{C})$ and B-site $({\mathrm{YNi}}_{2}{\mathrm{B}}_{2}\mathrm{C})$ are calculated and agree with experimental data. We also point out that the physical origin of this relatively large EFG on the Gd site results from a strong cancellation between positive $6p\ensuremath{-}6p$ and negative $5p\ensuremath{-}5p$ contributions.