getting the column names of a table

  • Thread starter Thread starter steve
  • Start date Start date
S

steve

hi,
how can i loop and get the field names of the columns in a dataset\s table?
I want the names of the columns (i.e. the field names) not the actual data.

TIA
 
Hi,

Assuming you are using sql server, build this dataset/datatable and then
simply loop through it with a datarow for each loop:

Dim dacolumns As New SqlDataAdapter("select distinct column_name from
information_schema.columns where table_name = '" & gl_xfilename & "' order
by column_name", oconn)

Dim dscolumns As New DataSet("columns")

dacolumns.Fill(dscolumns, "columns")

Dim irow As DataRow

For Each irow In dscolumns.Tables(0).Rows

columnbox.Items.Add(irow("column_name"))

Next

HTH,

Bernie Yaeger
 
Hi Steve,

Psuedo code....

For I = 0 to dataset.Tables(0).Columns.Count
MsgBox(dataset.Tables(0).Columns.Item(I).ColumnName
Next
 

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