Question get somthing like alias from a sql database column

pooya1072

Well-known member
Joined
Jul 5, 2012
Messages
84
Programming Experience
Beginner
hi
i have a datagridview in my form that get data from a sql database through a datatable .
in database tables has a name that it use as datatable's column headerName.but i want to named column headerNames by a different name like alias of each column of sql table .
but i dont know how can get an alias name or a description of each database column ( as alias ) from database . please help me about it .
 
Presumably you know ahead of time what the columns are and what you want them to be displayed as so you would build that into your application rather than the database. You can do it using your SQL code, e.g.
VB.NET:
SELECT GivenName AS [Given Name], FamilyName AS [Family Name] FROM Person
I've never tried this but I believe that you can also set the Caption property of each DataColumn in your DataTable and then, when you bind that DataTable to a DataGridView, the Caption will be displayed rather than the ColumnName. You can always add the columns to the grid yourself at design time and set their header text explicitly.
 
Back
Top