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.
Asked
Active
Viewed 402 times
0
-
And what issue you are facing in that? – Chetan Jun 10 '19 at 12:55
-
I'm certain you've made an attempt at solving this, right? Please show the code that you tried unsuccessfully, it's often just a tiny fix to your code that's required. – Sergey Kalinichenko Jun 10 '19 at 12:55
-
By "without iterating on it" do you mean not using loop syntax in your code, therefore allowing LINQ, row operations etc? Or do you actually mean not iterating over it period, including doing so in the external code? – Bartłomiej Popielarz Jun 10 '19 at 13:04
-
@ChetanRanpariya no I didn't face any error. Was just asking for possibilities. – Aamir Nakhwa Jun 10 '19 at 13:09
-
@BartłomiejPopielarz yes no loop syntax in my code. Linq etc are fine. – Aamir Nakhwa Jun 10 '19 at 13:10
-
You can access directly by index `dt.Rows[0][0];` – André Sanson Jun 10 '19 at 13:19
-
@AndréSanson Yes I can but I want list not a single date. – Aamir Nakhwa Jun 10 '19 at 13:27
1 Answers
1
List<DatetTime> = (from DataRow row in dt.Rows select (DateTime)row["ReportDate"]).ToList();

Aamir Nakhwa
- 393
- 1
- 12
-
-
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