Template Updation

How can i update the Databases with a template programatically…

I should be able to select the databases i want from the List and i would like to select a Particular Templates available on the server with which i would like to replace the selected databases…

Any suggestions … Please

Thanx in advance

Sri