I retrive data from a table to a datagridview.
I want the coulmns to be in a sorted according to their names
ex: column starting with 'a' should come before that of 'b' and so on
Is there any SQL querry for the above problem or any function in datagridview which can be used.

Recommended Answers

All 3 Replies

Hi, you can Use
ORDER BY FieldName SQL in Queries. This will sort and Display in sorted order in DataGridView.
Syntax

SELECT fieldlist
FROM table
WHERE selectcriteria
[ORDER BY field1 [ASC | DESC ][, field2 [ASC | DESC ]][, ...]]]

Ex

SELECT LastName, FirstName
FROM Employees
ORDER BY LastName;

SELECT LastName, FirstName
FROM Employees
ORDER BY LastName ASC;

I think he means that the column (i.e. field names) names must be sorted. Not the records

I think he means that the column (i.e. field names) names must be sorted. Not the records

Ya, Sorry I was mistaken.

I want the coulmns to be in a sorted according to their names
ex: column starting with 'a' should come before that of 'b' and so on
Is there any SQL querry for the above problem or any function in datagridview which can be used.

One solution: Give the fields in ascending order in your SQL query. Or sort the fields by own and generate the SQL query on it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.