how can i check if an entire column has same value or an entire row has same value from a datatable.
We have option to remove duplicates. Kindly check this activity and see if it suffixes your requirement
If you want to check the entire column with the same value you can use the below LINQ Expression,
-> Bool_SameValue = If(dt_ExcelData.AsEnumerable().Select(Function(x) x("Column name").ToString()).Distinct().Count() > 1, False, True)
Bool_SameValue is the boolean datatype variable, if the column have same values it will give True else False as output.
Hope it helps!!
You can use LINQ query to find the same value in columns and rows.
1. Check if an Entire Column Has the Same Value
Example:
Assume you have a DataTable named dt and want to check if the column named "ColumnName" has the same value:
(From row In dt.AsEnumerable()
Select row("ColumnName").ToString).Distinct().Count() = 1
2. Check if an Entire Row Has the Same Value
To check if all values in a specific row are the same:
Example:
Assume you want to check if the first row has the same value for all its columns:
dt.Rows(0).ItemArray.Distinct().Count() = 1
Thanks!!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.