fixed the write to databasecommand