LINQ Select From DataTable

ado.net, c#, linq

Solution

You're defining your query but not actually running it.

Your line:

dataGridView1.DataSource = q;

Needs to be:

dataGridView1.DataSource = q.AsDataView();

Problem

Just started to play around with datatable and LINQ today. I have a datatable that gets a list of Names From SQL database. I am looking to return a specific name from the dt using LINQ. I have tried the following code with no success at this. Is there something that i am doing wrong with the code. dt returns a full list of names i am just looking to reduce the names down to one name. There is a name in the adventureworks database called Blade i am trying to display this only. ``` DataTable dt = DAL.GetNames(); try { var q = from myrow in dt.AsEnumerable() where myrow.Field<string>("Name") =="Blade" select myrow; dataGridView1.DataSource = q; } ``` I have tried to replace the == with a .equals. I am totally new to the concept of using a Language intergrated query. when i run the code noting happens i dont get any errors ect just no data returned.

Original source