|
-
Sep 24th, 2008, 03:20 PM
#1
Thread Starter
New Member
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?
-
Sep 24th, 2008, 04:04 PM
#2
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 -
-
Sep 24th, 2008, 04:42 PM
#3
Thread Starter
New Member
Re: Retrieving column names from bound table
 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
-
Sep 24th, 2008, 05:20 PM
#4
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|