Hi, I would like to count number of rows in Datatable using Select Method.
My syntax currently looks like this:
Count = datatable.Select(“[ColumnName1] = '”+variable1+“'” and “[ColumnName2]” isnot Nothing).count
There was no validation errors until I added the part after “and”, how do I write the syntax to select rows where a specific column is not empty?
balupad14
(Balamurugan)
2
Hi @inyourgravity,
You can use like this
dtExcel.Select(“Condition”).CopyToDataTable().Rows.Count
or
Declare DataRow Array named “drArr”
drArr=dtExcel.Select(“Condition”)
Count=drArr.Length
Regards
Balamurugan
But how do I write the “condition”?
the condition i input in the select filters is having validation error, not the count part.
balupad14
(Balamurugan)
4
Count = datatable.Select(“[ColumnName1] = ‘”+variable1+“’” and “[ColumnName2]” isnot Nothing).CopyToDataTable().Rows.Count
Regards
Balamurugan
still getting the error “option strict on disallows implicit conversations from ‘string’ to ‘boolean’”
balupad14
(Balamurugan)
6
hi @inyourgravity,
the Count variable should be int32
Regards
Balamurugan
MAHESH1
(MAHESHKUMAR JV)
7
@inyourgravity
intCount= datatable.Select(“[ColumnName1] = ‘”+variable1+“’and [ColumnName2] <>'”+string.Empty+“'”).count
Regards,
Mahesh
already did so.
and “[ColumnName2]” isnot Nothing
this part is giving the error. once it is removed, there isnt any error.
‘string’ is just an empty string variable?
MAHESH1
(MAHESHKUMAR JV)
10
@inyourgravity
Yes string.Empty means empty value
balupad14
(Balamurugan)
11
Hi @inyourgravity
As @MAHESH1 is also right to apply the
Regards
Balamurugan
1 Like
Hi @inyourgravity just another way to solve this problem (and easier) its:
datatable.Rows.Cast(of DataRow).Select(function(row) row(yourColumnIndex).tostring=variable1 AndAlso not string.isnullorwhitespace(row(yourOtherColumnIndex).tostring).Count
DieGo_D
(Diego A Chacon G)
13
Hi, i resolved at this way:
userDT.Select(“Status is not Null”).CopyToDataTable().Rows.Count
1 Like
bhush
(Bhushan)
14
DT.Select(“[ColumnName] NOT is Null”)
or
DT.Select(“[ColumnName] is not Null”)
1 Like