0

How to get the total of specific column contains with specific string drom datatable.

I followed as like below but not getting :

int count = _dt.AsEnumerable().Where(c => c.Field<string> 
("EffectiveShow").Equals("0")).count;

There "EffectiveShow" is my column name. In that column I need the count of string "0".

Srikanth Reddy
  • 117
  • 2
  • 9

1 Answers1

0

Try this;

int count = _dt.AsEnumerable().Where(c => c["EffectiveShow"].ToString()=="0").ToList().Count;
bolt19
  • 1,963
  • 4
  • 32
  • 41
Nikunj Kakadiya
  • 2,689
  • 2
  • 20
  • 35
  • Error 104 'System.Data.EnumerableRowCollection' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Data.EnumerableRowCollection' could be found (are you missing a using directive or an assembly reference?) Getting this error. – Srikanth Reddy Jan 30 '17 at 08:10
  • I think you don't need to convert it to list, just call `.Count()` on .Where results. – Ali Baig Jan 30 '17 at 08:16
  • No, it's not getting even directly appending to where. It's generating error like inaccessible of count. – Srikanth Reddy Jan 30 '17 at 10:35
  • You could try this var results = from r in _dt where r.EffectiveShow == "0" select r; var count = results.Count(); – Nikunj Kakadiya Jan 30 '17 at 14:12