We report first-principles total-energy calculations on the adsorption of (3, 3) and (4, 4) single-walled carbon nanotubes (SWCNTs) on clean and hydrogenated diamond (100) surfaces. For the nanotubes adsorbed on the clean surface we find that the stable geometries for the nanotubes are on top of dimer rows and between two consecutive dimer rows where C-C chemical bonds between carbons of the nanotubes and the surface dimers are formed. The binding energies for a (3, 3) nanotube at the two sites are 2.26 and 0.83 eV angstrom(-1), while they are 1.74 and 0.36 eV angstrom(-1) for a (4, 4) nanotube. Our results show that to reach the stable geometry the nanotubes initially experience weakly adsorbed states at the position similar to 2.6 angstrom above the surface and then overcome a barrier of similar to 0.7 eV. Concerning the electronic properties, the most noticeable feature is that for the most stable geometry the electronic structure of the adsorbed metallic nanotube becomes semiconducting, i. e. a small band gap appears, due to the formation of C-C bonds between the nanotube and the dimer atoms. As a result, the adsorbed metallic nanotubes are realized in a metal-to-semiconductor transition. In contrast, on the fully hydrogenated C(100) surface, the nanotubes are weakly adsorbed on the surface, preserving an almost unchanged metallic character.