im getting error here
given:
bananaCount = fruitTable.AsEnumerable().Where(Function(row) row.ItemArray.Contains(“Banana”)).Count()
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
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?
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
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()
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.