Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I would like known when I export data from SQl to datagriview will automatic add a number after header name. Some headers have same name and in datagrid look like: Nazev1, Nazev2,Nazev3 why? I want only name: nazev. - auto renaming to Nazev 1, Nazev2. How can I fix it?

thank you

What I have tried:

Define in SQL
VPrikazMzdyAZmetkyPostup.nazev AS [Nazev]

VPrikazMzdyAZmetkySmena.nazev AS [Nazev]
Posted
Updated 31-May-19 0:53am
v2

When you write your SQL SELECT query you specify the header text (assuming you use a DataTable or DataSet as the DataSource):
SQL
SELECT A, B, C FROM MyTable
Will give you a DGV like this:
A   B   C
1   2   3
4   5   6
When you want specific text, you use AS:
SQL
SELECT A AS [Column number one], B AS [Charles XII], C AS Hello FROM MyTable
And you will get the headers:
Column number one    Charles XII    Hello
                1              2        3
                4              5        6
 
Share this answer
 
Depending on the usage context, you may not be able to have multiple columns with the same name- an instance would be when it is a control which must have a unique name.
Can I have multiple DataGridViews with columns with the same name? : csharp[^]

Of course, there is always trickery that can be used to overcome this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900