How to return a DataTable with Dapper?

c# dapper

Question

In one situation, I have to return aDataTable from a Dapper search. How do I send back aDataTable from a Dapper-based query?

DataTable dt = connection.Query("SELECT * FROM table");
1
13
3/26/2018 2:10:20 PM

Accepted Answer

There will be no benefit to utilizing Dapper in a situation involvingDataSet . And in particular, your particular example (without any arguments etc.) is so unimportant that you could just as well useExecuteReader either directly or aDbDataAdapter

I am, however, willing to make a dapper API available that exposes theIDataReader You may feed any consumer with the API from Dapper,DataSet / DataTable included. But I must ask: What would be the point if dapper were used to do this example? Although I'm damned happy with how the parameter handling turned out, it could make more sense if you were at least using dapper.

10
7/19/2013 9:42:28 PM

Popular Answer

Huh? Dapper solely offers ADO.NET extension methods, saving you the trouble of dealing with DataTables and DataSets!

If you want DataTables and DataSets, you may still utilize vanilla ADO.NET SqlDataAdapter, which will provide you with all the DataTables you could ever want.



Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow