1

When I use SQL statement such as

select
    ID as ID,
    Name as CustomerName,
    Day1 as BirthDay,
    Day2 as MemberDay
from [Customer]

to populate a DataGridView (Named poorly for demonstration purpose),

It will name the columns' Name AND HeaderText automatically. (Both ID, CustomerName, BirthDay, and MemberDay)

Is there a way to set the Name and HeaderText differently from the SQL statement itself?

Or I just have to rename each HeaderText individually?

Thank you very much for your help!

Edit

Because the SQL statement might be different depend on the user's choice, so it'll be tedious to rename each HeaderText.

Of course it's not impossible to do, but I have to consider all possible situations and handle it accordingly, possible but tiresome and bad practice.

And mostly importantly, it needs to be written back to the database from the DataGridView once the user edited the content.

And I can't find the original column name from the DataGridView itself, that's why I'm trying to looking for a better way to resolve it.

Thank you very much for you help!

PiggyChu001
  • 440
  • 6
  • 20

1 Answers1

0

You can use a form of SQL SELECT AS to rename columns in your query results.

So far you’ve seen where queries results return results named after the table columns.

Name the column [Distinct Names].

select
    ID as [Customer ID],
    Name as [Customer Name(First and Last)],
    Day1 as [Date of Birth],
    Day2 as [Member Since]
from [Customer]