Reputation: 5755
I'm curious is there any built in method that can count the number of columns in an sql query based on the DataReader result. (I'm not talking about "SELECT COUNT(*) FROM X"
)
For example this can be carried out in Java by using the ResultSetMetaData
class that has a .getColumnCount()
method. This is useful when formatting and putting the results of a query in a list without actually knowing how many columns there are.
I'd like know if such method exists in C# as well.
Upvotes: 1
Views: 84
Reputation: 751
You can find it on the SchemaTable for the data reader:
dataReader.GetSchemaTable().Columns.Count
Upvotes: 2