0

I have a stored procedure which returned a datatable which have only 1 date column. I want to fill List from that datatable without using a loop.

mjwills
  • 23,389
  • 6
  • 40
  • 63
Aamir Nakhwa
  • 393
  • 1
  • 12

1 Answers1

1
List<DatetTime> = (from DataRow row in dt.Rows select (DateTime)row["ReportDate"]).ToList();
Aamir Nakhwa
  • 393
  • 1
  • 12
  • This is correct approach. – Chetan Jun 10 '19 at 13:19
  • If the sole purpose of the existence of the data table is as a means to extract the data into the list, you can skip it all together using any class derived from DbDataReader (which implements IEnumerable) as a base for a LINQ expression. In the process you'll get rid of all the intermediary allocations done to populate the data table. – Alfred Myers Jun 10 '19 at 13:46