Is your intent to use a database bound template? If so, you can put the ID query field (your data source will have both query and data fields) on the form, have the user type in the ID and have a rule on that field that runs the query.
If your intent is to not use a database bound template, you'll probably want a web service that you can use to only get the data from the DB related to the entered user ID, so you don't have to load all the data - we sell a really nice one here. In that case, you'd have a main data source field on the form the user can enter an ID into, and whatever rules you need to query your data on that field.
If your intent is to just load all the data from SQL and then use filtered XPath to set field values, you can do that too - but you'll see some performance hit unless your table is small.
The general idea for all these is the same - your rules need to be on the field where the user enters the ID.