I am executing a stored procedure with Dapper like this:
var sprocResult = conn.Query("TestSproc", new {clientID = 2}, commandType: CommandType.StoredProcedure).ToList();
I can enumerate the results and list the values. What I need to be able to do though is also enumerate the field names that come back from the sproc. I will not know these field names at design time.
Thanks in advance.
When using the dynamic API (the Query(...) instead of Query<T>(...), as per your example), each row also implements IDictionary<string,object>. So basically:
foreach(IDictionary<string,object> row in sprocResult)
{
var colNames = row.Keys;
//...
}
If the query may return no rows, the Query().First().Keys does not work. In this case, you can use ExecuteReader().GetName(i).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With