First-principle calculations were performed for the study of the superconductor MgB2 and AlB2. The doping effect of compound Mg1-xAlxB2 was analyzed by supercell method. Band structure, electronic bands structure, total and partial densities of states were calculated and analyzed in detail. Covalent bond effects (CBC) appeared in the electronic bands structure when doping Al to MgB2. It is found that this CBC effects on Mg1-xAlxB2 samples have prominent relations to superconductivity. The study of the density of state indicates that the superconductivity decreases with the increase of compound Al. In particular, there exists the transition of superconductor to non-superconductor with the change of x. The theoretical predictions agreed well with experimental measurements.