DataSource a Linq(ed) DataTable example

if u ever tried to query with Linq a datatable and then assign it to a DataGridView (and other stuff i guess) then u might have noticed that the grid shows the properties of the DataRow(s).
And if you tried to select the ItemArray, again a mess.
Sooo... its so simple i laugh at myself but i must:

var query =
     from data in tblAllData.AsEnumerable()
     where data.Field<DateTime>("Start").Month == (int)cmbMonths.SelectedValue
     select data;
if (query.Count() > 0)                
    dgvMain.DataSource = query.CopyToDataTable();



Popular posts from this blog

c# Service Play Sound with NAudio example by Moshe

Asp.Net Ending Response options, Response.End() vs CompleteRequest()

JS/JQ simulate Enter event