Also you need to post the definitions for all the variables used in the posted code.
For example what is driver? Or By?