David H. Smith, 64, retired principal and teacher of science and agriculture at Banneker School in St. Mary's County, Md., died of cancer Monday at Southern Maryland Hospital Center in Clinton, Md. He had been ill since December.

Mr. Smith's 38-year teaching career began and ended at the Banneker School. He taught agriculture and science until 1962, when he was made principal. He was principal until his retirement in 1975.

In addition to his regular teaching, Mr. Smith taught evening adult classes in agriculture as part of a government-sponsored program to aid veterans, and other adults, during World War II. The purpose of his program was to help veterans and others in St. Mary's County learn how to develop better crops and livestock.

Mr. Smith was born in Garland, N.C., and grew up there. He attended the Agricultural and Technical College of North Carolina at Greensboro, where he earned a B.A. in agricultural education. In 1937, he moved to St. Mary's County to teach school and spent his summers working toward a master's degree. Soon after earning a M.A. in administration from New York University in 1961, he became principal of the Banneker School.

He lived in St. Mary's County with his growing family for about seven years before moving to a small farm he bought in Clinton, where he and his wife brought up their nine children.

Mr. Smith's spare time was spent tending his small farm - he called it gardening - where he raised livestock, vegetables and fruit trees. His other favorite pastime was fishing and after his retirement de devoted much of his time to these activities.

He was a dounding member of the Clinton United Methodist Church, where he taught Sunday school for many years and was a member of the board and an officer of the men's club.

Mr. Smith's survivors include his wife, Alice Frederick Smith, of the home in Clinton, a teacher in the Prince George's County school system, and his nine children, David Ronald, of District Heights; Frederick Tory, of Clinton; Tyrrell P., of Columbia, Md.; Ethan X., of Chesapeake Beach; Anthony C., of Palmer Park; Gary J., of Oxon Hill; Reynaud G., of Towson, Md.; Gwendolyn S. Brown, oF Washington, and Karen D., of Clinton.

In addition, he is survived by five sisters and a brother, Ethel Centers, of New York City; Cornelia Brewington, of Newark, N.J., and Dorothy Hayes, Sudia Green, Myrtle Smith and Ulysses, all of Garland, N.C., and 11 grandchildren.