CGhoST
(John)
October 11, 2019, 1:57am
1
I have a Output Data table activity which has converted a select in a Data Table to String.
35,29,7,128,12,35,3,26,48,32
I also have a variable named NumberCheck which is assigned as Int32 and has a value of 5.
How do i make a if statement that can check if the Int32 variable exists in the above string?
The query i have doesn’t work:
If CInt(Datatable2).Contains(NumberCheck)
The error stated is Contain is not a member of ‘Integer’.
If i do NumberCheck.ToString then it works but it sees 35 as 5 and gives true being text.
lakshman
(Ganta lakshman)
October 11, 2019, 2:56am
2
@CGhoST
Why you are converting DataTable into string.
You can use ForEach Row activity to iterate DataTable and then check whether this DataTable contains required value or not. i.e.NumberCheck
ForEach row in yourDT
If Cint(row(“Column name”).Tostring) = Number heck
Then print True
Else print False
CGhoST
(John)
October 11, 2019, 3:10am
3
I wanted to avoid a ForEach loop because what i gave was an example. I need to iterate over 1000 columns with number data and contain would do it straight away.
Is there any other way?
lakshman
(Ganta lakshman)
October 11, 2019, 3:16am
4
@CGhoST
Ok.
newDT = yourDT.Select("ColumnName = '"+NumberCheck.Tostring+"').CopyToDataTable
If newDT.Rows.Count > 0
Then it contains that value
Else no
CGhoST
(John)
October 11, 2019, 3:51am
5
@lakshman
What if the columns have no header and are [F1], [F2], [F3], [F4], etc…
How does it iterate through all the columns please?
lakshman
(Ganta lakshman)
October 11, 2019, 4:20am
6
@CGhoST
Try below LINQ query.
newDT = yourDT.AsEnumerable.Where(Function(row) Cint(row.Item(5).ToString) = 5).CopyToDataTable
Here 5 refers to F column.
CGhoST
(John)
October 11, 2019, 12:16pm
7
@lakshman
Sorry I don’t understand. Could you make a small project to show me with data table please.
amaresan
(Amaran)
October 11, 2019, 1:47pm
8
@CGhoST
refer below xaml
After converting string use below code in log or message box
StrTableOutput.Split({VbCrLf,“,”},StringSplitOptions.RemoveEmptyEntries).Contains(CStr(intSerachValue)).ToString
Main.xaml (8.1 KB)
1 Like
CGhoST
(John)
October 11, 2019, 3:07pm
9
@amaresan
Thank you so much. This worked perfectly.
1 Like
system
(system)
Closed
October 14, 2019, 3:07pm
10
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.