@Using like operator in data table


#1

Hi Team,

I tried passing the below code to get matching columns starts with 1
Fixed vend is a column name and values as shown below:
Fixed Vend
1008908
1008908
1008908
1003389
1001375
MK-US2
MK-US2
MK-US2
MK-US2

datarow[] MainTable2=DT1.Select("[Fixed vend] LIKE ‘1*’")

it is thowing conversion error as shown below:
Please help on this.

Thanks
Girish


#3

This error will pop up if there is a datatype mismatch. In this case, please check the type of your excel cells. It appears that the type is not text in your case. Please change the column to text and then check, it should work.

OR rather, you can convert the column in the select method itself :slight_smile: ::

datarow[] MainTable2=DT1.Select(“Convert([Fixed vend],‘System.String’) LIKE ‘1*’”)

Let me know if this works for you.


#4


#5

Can you post your complete select statement? and if possible attach your excel along with xaml. :slight_smile:


#6

DT1.Select(“Convert([Fixed vend],‘System.String’) LIKE ‘1*’”)


#7

Main.xaml (20.1 KB)
InputExcelSheet.xlsx (46.5 KB)


#8

Or, assuming this is what you want, you could use the fact that the numbers are already doubles and go for

DT1.Select("Col >= 1.0 and Col < 2.0")

#9

Main.xaml (20.1 KB)
Hey, Please try with the attached xaml. There was some syntax error. It’s working perfectly fine now.
Let me know if it works for you. :slight_smile:


#10

Hi Prakshi,

Thank you.

Regards
Girish


#11

Anytime. :slight_smile:
Please mark it as solution for others’ reference. :slight_smile:

Regards,
Prakshi Tyagi