Suppose table1 is having colmn_name with value A B C.
Table 2 is having column A B C with some values.
First fire query on table1 to get columns in variabl.
Use comma separated login for that.
Declare @SelectColum varchar(max)
SELECT @SelectColum = SUBSTRING(
(SELECT ',' + s.colmn_name
FROM table1 s
ORDER BY s.colmn_name
FOR XML PATH('')),2,200000) AS CSV
Select @SelectColum from table2
You dont need to do any coding in C#. Just use above logic in sql to get data.
If still having doubt then explore your database design. (What is relation in table?
column name? What output you want?