SQLTeam.com | Weblogs | Forums

I know this much be a dumb question


Considering I've been a programmer for over 33 years but...

Ok, I'm doing Visual Studio 2013, C#, and SQL. Now with GridView boxes If I just populate the box with direct SQL statements it shows the column names as the names in the GridView. Now I can make a 'SELECT this_field AS "This is the new field", etc... and the name 'This is a new field" will show up at the top of the GridView.

But, I seem to remember somewhere that SQL CREATE statements you can assign aliases for the fields names and they will show up in the GridView as the name of the column.

Any idea how to do this syntactically?



CREATE TABLE assigns the names and types of columns. You can assign aliases at SELECT time, as you did.


So there is no way to do it with the table itself?

In the CREATE we have such as:
id_agreement integer,
id_company_payor integer,
id_company_land integer,
id_contact integer,

But no way to have 'Agreement ID' or 'Company Payor ID' alias in the create statement, right?


right, only in a subsequent query


You could create a view and then do all selects against that view. For example,

CREATE VIEW dbo.YourViewName
	id_agreement AS [Agreeement ID],
	id_company_payor [Company Payor ID], 
	id_company_land [Company Land ID], 
	id_contact [Contact ID]


You could use a Computed Column, but I think they stink ...

I'd use a VIEW (and put both the "Pretty Name" and the original column name in the SELECT list to enable people to use either (if that is what you need), otherwise have the VIEW for Pretty Names and the table for Original Column Names


Well the view may be the only way to go folks.

What I did do, for right not, is make at the first of the c# public partial class many string objects with the names I wanted in the form for each SQL column, then when constructing the SQL statement I added those as part of the statement.

At least that way I could reuse them in other parts of the form for other SQL statements I have to make (we use a filter where you put, say the owner or offer number and the SQL selects by one of them to get the data).

Then building the select with another string object and using that as part of the NpgsqlDataAdapter to execute it.

Thanks for the advice.