It depends on what two different databases mean. If two databases are running on the same SQL server, it is easy to access the table of another database
SELECT * FROM OtherDb.dbo.TableOnOtherDb
If not, I would suggest you create a database link between the two databases (see the SO question. How do I create and query related database servers in SQL Server? ). Then you can access another table as above.
In both cases, you can use the JOIN query to join two tables. Then you need only one data reader
SELECT A.Index_no, A.emp_ID, A.contact_no, B.emp_name, B.salary, B.dept FROM table1 A INNER JOIN table2 B ON A.Index_no = B.Index_no WHERE B.salary < 20000 ORDER BY B.emp_name
UPDATE
If the number of records involved is small, then querying the second table only once with the IN clause will be much more efficient if for some reason you cannot connect the two servers.
SELECT * FROM table1 WHERE Index_no IN (4,12,17,30,112,167)
You would create this SQL statement like this
string[] stringArray = array1 .Select(i => i.ToString()) .ToArray(); string list = String.Join(",", stringArray); string sql = "SELECT * FROM table1 WHERE Index_No IN (" + list + ")";
The idiomatic way to execute the second loop would be (not do while )
for (int i = 0; i < array1.Length; i++) { ... }