How to query DataGridView using Linq

I have a DataGridView that I want to query using Linq (C # WinForm). I want to "count" lines where certain criteria are met. For example,

variable1 = "count rows where ColumnBoxAge > 3 || < 5"

label1.Text = variable1

      

How can I do this in C # WinForm using Linq?

+1


source to share


3 answers


I don't know if it might work, but you can try this:

dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>("ageColumn") > 3 ||
     c.Field<int>("ageColumn") < 5).Count();

      



Edit: where instead of Select.

+2


source


So, your request is wrong! Try '& &' instead of '||';

dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>("ageColumn") > 3 &&
     c.Field<int>("ageColumn") < 5).Count();

      



Edit: where instead of Select.

0


source


@yapiskan

dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>("ageColumn") > 3 &&
     c.Field<int>("ageColumn") < 5).Count();

      

... Where instead of. Please select

Many thanks! I appreciate your help.

0


source







All Articles