HighTechTalks DotNet Forums  

How to get database column alias from datatable

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss How to get database column alias from datatable in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
mohaaron@gmail.com
 
Posts: n/a

Default How to get database column alias from datatable - 01-03-2008 , 04:50 PM






Does anyone know how I get can to the column alias in a datatable?
here is an example of what I need to do.

Query:
select Column1 as [My Column 1], Column2 as [My Column 2] from
dbo.tablename

Now I need to generate the BoundFields after the query is executed.

foreach (DataColumn column in dataView.Table.Columns)
{
BoundField boundField = new BoundField();
boundField.DataField = column.ColumnName;
boundField.HeaderText = column.Alias;
this.searchGrid.Columns.Add(boundField);
}

The problem is that there is no column.Alias so how can I get the
original column name for the DataField and then the Alias for the
HeaderText?

thanks

Reply With Quote
  #2  
Old   
Miha Markic
 
Posts: n/a

Default Re: How to get database column alias from datatable - 01-04-2008 , 03:20 AM






Simple: you can't as this piece of information is never transmited.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

<mohaaron (AT) gmail (DOT) com> wrote

Quote:
Does anyone know how I get can to the column alias in a datatable?
here is an example of what I need to do.

Query:
select Column1 as [My Column 1], Column2 as [My Column 2] from
dbo.tablename

Now I need to generate the BoundFields after the query is executed.

foreach (DataColumn column in dataView.Table.Columns)
{
BoundField boundField = new BoundField();
boundField.DataField = column.ColumnName;
boundField.HeaderText = column.Alias;
this.searchGrid.Columns.Add(boundField);
}

The problem is that there is no column.Alias so how can I get the
original column name for the DataField and then the Alias for the
HeaderText?

thanks


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.