Return list of columns in user-provided subquery I am trying to fill a ComboBox of all columns from results of a query. That query is submitted by the user on the form, so the program needs to run the query then have a procedure run that extracts just the column names. I know the following works for a typical table:

SELECT
    c.name 'Column Name'
FROM
    sys.columns c
WHERE
    c.object_id = OBJECT_ID('Vendor')


What would be the best way to insert the user query (select * from vendor) as a subselect and get the same result? 

Edit:
I could do(as Thomas Stringer noted): 

for (int i=0; i &lt; dataSet.Tables["Vendor"].Columns.Count; i++ )
{
    ColumnChoices.Items.Add(dataSet.Tables["Vendor"].Columns[i].ColumnName.ToString());
}


...though that isn't very efficient because it requires loading all of the data into the dataset when I really only want the columns.
Just pull the DataTable object(s) and enumerate the DataColumnCollection.  Here is some sample code to show how you can enumerate the collection and dump the column names:

DataTable queryResults = // get your data

foreach (DataColumn column in queryResults.Columns)
    Console.WriteLine("Column Name :: {0}", column.ColumnName);


Of course this is an extremely rudimentary illustration, but it shows what you need: