Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vb.net, how to get the column names from a datatable

So i create a datatable from a table i can't directly view(i.e. using sql server management). I want to find the column names that are in the datatable, what would be the correct way do this?

like image 235
hi.im.new Avatar asked Jul 22 '11 14:07

hi.im.new


People also ask

How do I get column names in SQL?

To get the column name of a table we use sp_help with the name of the object or table name. sp_columns returns all the column names of the object. The following query will return the table's column names: sp_columns @table_name = 'News'

What is a column name?

In an aggregate function, a column name specifies all values of the column in the group or intermediate result table to which the function is applied. Groups and intermediate result tables are explained under Queries.

How do I set COL names in R?

Method 1: using colnames() method colnames() method in R is used to rename and replace the column names of the data frame in R. The columns of the data frame can be renamed by specifying the new column names as a vector. The new name replaces the corresponding old name of the column in the data frame.

What is a DataTable in C#?

In the ADO.NET library, C# DataTable is a central object. It represents the database tables that provide a collection of rows and columns in grid form. There are different ways to create rows and columns in the DataTable.


1 Answers

This is how to retrieve a Column Name from a DataColumn:

MyDataTable.Columns(1).ColumnName 

To get the name of all DataColumns within your DataTable:

Dim name(DT.Columns.Count) As String
Dim i As Integer = 0
For Each column As DataColumn In DT.Columns
  name(i) = column.ColumnName
  i += 1
Next

References

  • Data Table (MSDN)
  • Data Column (MSDN)
like image 62
Brian Webster Avatar answered Oct 31 '22 03:10

Brian Webster