c# - Create a list of DataTables from a single DataTable, but grouped by day -
i hope can me puzzling question!
in past i've used following statement in order obtain list<datatable>
each datatable
in list comprises of records each of distinct names in "name" column of "inputdt" datatable.
in other words, code outputs list of tables each table contains data specific name:
list<datatable> listofserialnumberdatatables = inputdt.asenumerable().groupby(row => row.field<string>("name")).select(g => g.copytodatatable()).tolist();
i similar thing, except group datetime
column, each of datatable
s in list<datatable>
comprises of records have same date (regardless of time).
so i'm trying create code creates list table in list<datatable>
contain data specific date.
so example, 1 of tables contain data dated 1st oct 2016, , table in list contain data 3rd oct, etc. [ps i'm not worried format of output of column - question list of datatables data in them specific day.]
[note - of dates in table. i'm not expecting empty list date not in datatable. apologies if that's obvious!]
where i'm at: after head-scratching i've come similar this, i'm not sure how finish off:
list<datatable> listofdaysforsingleserialno = datatable.asenumerable().groupby(x => entityfunctions.truncatetime(x.field<datetime>("dateofresult"))).<what goes here?>
i'm baffled. can help? possible using linq?
thank in advance kind assistance everybody.
if understand correctly want exact same thing except on different column. thing should change expression going groupby()
method:
list<datatable> listofdaysforsingleserialno = datatable.asenumerable().groupby(x => x.field<datetime>("dateofresult").date).select(g => g.copytodatatable()).tolist();
edit: entityfunctions.truncatetime
method works linq entities (msdn), groupby()
cannot use it. instead can date
property of datetime
.
Comments
Post a Comment