pk123
September 29, 2022, 12:59am
1
The “AND” or “OR” in the Datatable.select is not working.
dtMasterTable.Select("[Column5] = ‘var1’ AND [Column9] = ‘var2’ ").Count.ToString
I am checking, if the particular combination of records from datatable 1(Iterating this Dt) is present in the datatable2 (dtMasterTable).
If I select the conditions separately, the data is retrieved but when I combine the conditions with “AND”, it’s not working.
Please let me know if I am missing something in the statement. Thanks in advance!!
jack.chan
(Jack Chan)
September 29, 2022, 1:11am
2
@pk123
does it work if you change AND to OR?
and is there a row where Column5 = var1 and Column9 = var2?
pk123
September 29, 2022, 1:17am
3
“OR” also is not working.
Yes, there is a matching row but I did some cleanup to get the matching data.
Below is the sample data
dtMasterTable:
Column5 123
Column9 1
dtTable2
column0 123
column4 '1
var1 = row(0).ToString().Trim()
var2 = row(4).ToString().Trim().Substring(1)
Removing ’ from row(4)
jack.chan
(Jack Chan)
September 29, 2022, 1:21am
4
are var1 and var2 variables?
if so it should be
dtMasterTable.Select("[Column5] = '"+var1+"' AND [Column9] = '"+var2+"'").Count.ToString
you can also print this line before the select statement to check your condition is correct
"[Column5] = '"+var1+"' AND [Column9] = '"+var2+"'"
pk123
September 29, 2022, 1:41am
5
This solution worked. Thank you so much!
Appreciate your quick response @jack.chan
Can you pls clarify the below syntax as well?
Not working dtMasterTable.Select("[Column5]=’ “+var1+” ’ AND [Column9]=’ “+var2+” ’ ")
vs
Working dtMasterTable.Select(“[Column5] = '”+var1+“’ AND [Column9] = '”+var2+“'”)
Wondering, if the spacing matters for the quotes.
1 Like
jack.chan
(Jack Chan)
September 29, 2022, 1:58am
7
it is the spacing ,
let say
var1=‘abc’
var2=‘def’
dtMasterTable.Select("[Column5]=’ “+var1+” ’ AND [Column9]=’ “+var2+” ’ ")
will translate to
dtMasterTable.Select("[Column5]=' abc ' AND [Column9]=' def '")
which is wrong
1 Like
pk123
September 29, 2022, 2:25am
8
Thanks for the clarification @jack.chan
1 Like
system
(system)
Closed
October 2, 2022, 2:25am
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.