How to check particular string in a datatable

Hi Everyone,

My Requiement is

  1. I have a datatable with one column ,values maybe “others” , “gec” , “md” , “md/gec” with no particular case
  2. I need to check whether datatable contains “md/gec” or “gec” then send mail to one particular mail id or if its not there send mail to another id
  3. so i have 3 rows in a datatable eg: “md” , “gec” and “others” , i should priortize “gec”
    5.but if i used select or lookup it requires case sensitive
    6.i cant use for each since i need to send mail
1 Like

Hi @kavya.s16 ,

Use Filterdatatable activity to filter out columns->select contains in it for your specific words.-> output a DT from it if Dt.rows.count >0 then you can send a mail.

Thanks

Hi @kavya.s16 welcome to community

You can perform this using Linq query

Please find the expression below

Use this in IF condition

(From r In DT Where r(your column name).toString.contains(“gec”)Select r).Count>0

DT in the above expression says Datatable Name so please change accordingly , also column name (please enter your column name)

So if count is greater than zero send a mail

Hi

Let’s make it in a simple method of using AsEnumerable if you have a datatable named dt

Use a IF activity like this with a condition

dt.AsEnumerable().Where(Function(a) a.Field(of String)(“yourcolumnname”).ToString.ToUpper.Contains(“MD/GEC”) OR a.Field(of String)(“yourcolumnname”).ToString.ToUpper.Contains(“GEC”)).CopyToDatatable().Rows.Count > 0

If it’s true it goes to THEN block which means there are records with those texts
So send mail to one mail I’d

Or goes to ELSE block where send to another mail I’d

Cheers @kavya.s16

If you need to check multiple conditions to filter. I would use array (or if you don’t know exact size use List) and filter

arrayVar = {“GEC”,“MD/GEC”}

in If activity = (From r In dt.AsEnumerable
Where arrayVar.Any(Function (x) r(“your column name”).ToString.ToUpper.Equals(x.ToUpper))
Select r).Count > 0

it’s easier to maintain in the future as well.

Hope that helps