I’ll chime in here and say that it’s far more efficient the original way you were doing this, than to be calling the “same” query 50 times (or however many fields you have). Travis Cox did a presentation on improving performance, and this was one thing he specifically mentioned. Personally, I would continue down the first route, but you don’t want to use that Window event, you would put your script inside the propertyChange event and look for a change in your passed in property. And as @bkarabinchak.psi already mentioned, make sure to name your components usefully, for example with the sql field name within it, so that you can easily write to these components within a loop.
E.g.
ds = system.db.runPrepQuery('SELECT ....')
pds = system.dataset.toPyDataSet(ds)
fieldNames = list(ds.getColumnNames())
for field in fieldNames:
event.source.getComponent("UserInput_{}".format(field)).text = pds[0][field]
** '{}'.format(field) will only work for Jython 2.7 (Ignition v8 and above). Use '%s' % field for v7
*** Not tested