Reset Device

Close #32
check database result for null pointers
Extract common code as funtions

QueryInt() and QueryString()