Results 1 to 4 of 4

Thread: Retrieving column names from bound table

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    15

    Retrieving column names from bound table

    Probably a really simple way to do this but I cant work out how or find any documentation on how to retrieve the column names of a table e.g. using the bindingsource
    could someone help?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Retrieving column names from bound table

    DataTable class has Columns property which returns a DataColumn collection. And DataColumn class has ColumnName property that gives you the name of the datacolumn.... Put all together, you will need to get the columns collection from the datatable and loop thru it to get the individual column names. Something like this:
    Code:
    Dim myDataTable As DataTable = CType(myBindingSource.DataSource, DataTable)
    For Each column As DataColumn In myDataTable.Columns
         MessageBox.Show(column.ColumnName)
    Next
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    15

    Re: Retrieving column names from bound table

    Quote Originally Posted by stanav
    DataTable class has Columns property which returns a DataColumn collection. And DataColumn class has ColumnName property that gives you the name of the datacolumn.... Put all together, you will need to get the columns collection from the datatable and loop thru it to get the individual column names. Something like this:
    Code:
    Dim myDataTable As DataTable = CType(myBindingSource.DataSource, DataTable)
    For Each column As DataColumn In myDataTable.Columns
         MessageBox.Show(column.ColumnName)
    Next
    That doesn't work as myBindingSource.DataSource returns a DataSet rather than the actual table in the DataSet

  4. #4

    Thread Starter
    New Member
    Join Date
    Aug 2008
    Posts
    15

    Re: Retrieving column names from bound table

    Nevermind got it sorted! thanks for the help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width