Welcome to the forum.
Is there a reason why you are doing it with code?
You can set either a data validation or a rule on the field in the form that would compare the value of the field witht he value in your secondardy source. You would just need to use a filter on your secondary possibly.
So an example would be the user enters a new company name in a field. I could add a rule that if the field is equal to the companyname field in my secondary data then trigger an alert and blank out the field or whatever. This would do a compare against all of the rows in your secondary and if a match was found return true and execute your actions. You could make this more complex with a filter but I think that is the direction you would want to pursue.
If you are working with data and various tables, I would recommend you check out the Database Accelerator.Qdabra Database Accelerator Suite Version 2.1 - Developer
It is a whole suite of web services. Web Services allow you to get around the limitations with InfoPath database forms only being able to query and submit to one table structure, etc. If you are developing enterprise solutions, it can help a lot with a bunch of built in features and tools which make things much easier.
If you would like a demo let me know.