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();

TADA!

Comments

Popular posts from this blog

OverTheWire[.com] Natas Walkthrough - JUST HINT, NO SPOILERS

SOLVED The item could not be indexed successfully because the item failed in the indexing subsystem

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