Populate collection object with field names from SQL table?

  • Thread starter Thread starter HillBilly
  • Start date Start date
I could use a little help on this seemingly arcane objective.

I am assuming you are using some flavour of Microsoft SQL.

There are a couple of ways I have heard of to get the column names
from SQL. If you are trying to get the column names from a table
without actually getting any data, you can run a select query on the
INFORMATION_SCHEMA.Columns view. But if you are running a select on a
table, say like a SELECT * ..., and you want the column names in the
resultset, you can use either the GetSchema method, or you can load
the data from a DataAdapter to a DataSet, and then to a DataTable,
where the DataTable object has a collection of Columns and it has a
Name property.
 
Thanks for the leads...

I could use a little help on this seemingly arcane objective.

I am assuming you are using some flavour of Microsoft SQL.

There are a couple of ways I have heard of to get the column names
from SQL. If you are trying to get the column names from a table
without actually getting any data, you can run a select query on the
INFORMATION_SCHEMA.Columns view. But if you are running a select on a
table, say like a SELECT * ..., and you want the column names in the
resultset, you can use either the GetSchema method, or you can load
the data from a DataAdapter to a DataSet, and then to a DataTable,
where the DataTable object has a collection of Columns and it has a
Name property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top