Count the banana from excel

im getting error here

given:
bananaCount = fruitTable.AsEnumerable().Where(Function(row) row.ItemArray.Contains(“Banana”)).Count()

count the banana from excel

fruitTable.AsEnumerable().Count(Function(row) row(0).ToString().ToLower() = "banana")

Hope it helps

Hi @Shravan_Pintu

Here is it.

Data.xlsx (7.9 KB)
Main.xaml (39.8 KB)

@Shravan_Pintu,

Use this LINQ. It will give you count from whole datatable.

intCount = (From row In dtInput.AsEnumerable() From col In dtInput.Columns.Cast(Of DataColumn) Where row(col).ToString().Equals("banana", StringComparison.OrdinalIgnoreCase) Select row(col)).Count()

Input:

Output:

Code:

how can i replace one banana with one mango?


im getting mango as 0

dtfruit.AsEnumerable().Count(Function(row) row(“Fruit1”).ToString.Equals(“mango”, StringComparison.OrdinalIgnoreCase)).ToString()

AND the output shoud be
banana:2
apple:3
orange:3
mango:1

@Shravan_Pintu,

Modify this way

intCount = (From row In dtInput.AsEnumerable() From col In dtInput.Columns.Cast(Of DataColumn) Where row(col).ToString().Equals("mango", StringComparison.OrdinalIgnoreCase) Select row(col)).Count()

Getting output as zero

(From row In dtfruit.AsEnumerable() Where row(“Fruit1”).ToString().Equals(“mango”, StringComparison.OrdinalIgnoreCase) Select row(“Fruit1”)).Count().ToString()

@Shravan_Pintu,

Use this LINQ as it is. No need to change anything like column name or anything. This query will automatically take column names

(From row In dtInput.AsEnumerable() From col In dtInput.Columns.Cast(Of DataColumn) Where row(col).ToString().Equals("mango", StringComparison.OrdinalIgnoreCase) Select row(col)).Count()

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.