Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get field names returned from any sql statement

Tags:

c#

sql

asp.net

I want to get a list of the field names returned from a sql statement. This can be done using a sql statement or some c# parsing code to parse the statement as a string. Can this be done easily without writing a complex parser?

For example I may want to return

name, field2, field3

from

SELECT a.field1 as name, a.field2, b.field3 FROM A INNER JOIN B ON A.Id = B.FkId
like image 444
Sheff Avatar asked Sep 13 '26 05:09

Sheff


1 Answers

If you are asking about using SqlClient components, such as the SqlDataReader Class, you can use the

Reader.GetName(columnNumber)

Method to return the column name.

like image 200
Adriaan Stander Avatar answered Sep 15 '26 20:09

Adriaan Stander