Search Datatable and write in it if found


#1

Hi All,
I have a doubt about data-table.
Let us think I have a data table dt1
Now I want to search the dt1 for a “sample_string” if found I should write something in the next cell.
Can any one help with out for each.
Thanks in advance.


#2

@harinred

1.If you want to search the dt1 for a “sample_string” ,use if condition inside the for each loop
dt1.Contains(“sample_string”) // if this condition is true
then store your values


#3

Hi Sob,

Thanks for immediate response, I don’t want to use for each, I have to achieve with .select method and once found I need to write in it.


#4

@harinred

If your excel file contains more than 1 row , then either we have to use for each or while loop.

If you can please elaborate your requirements.


#5

Okay let me explain,
I need to search for a specific invoice number in the datatbale dt1 which has 5 columns and 1st column is Invoice. If I find the invoice in the first column then I need to write the status in 5th column. Also I know that I can search my dt1 by using .select method but I dont know how to write inside the dt1 once found.


#6

Hi @harinred

is there any reason why you can’t use for each row ?

its harder to do what you want without it. It requires more activities and more logic.

Regards


#7

I believe you can achieve this with Select method. If this is what you are looking for,

Use Assign Activity as below:
dtRowArray = dtTable.Select(“Your Query”)

where dtRowArray is your DataRow[] & dtTable is the DataTable.

For your reference,

Thanks,
Rammohan B.


#8

Hi Pablo,
Thanks for the quick response. But I assume that for each needs more steps than .select method and for each is more time consuming compared to .select. Correct me if I am wrong.


#9

@harinred I belive that For each row with 5 columns won’t take so much time… if you arent able to make it with select activity, try this and check the time it spend processing.

Regards!


#10

Hi Ram,

First of all I would like to thank all of you guys for sparing time.

This is not exactly what I am looking for.
I know that dt.select(“string”) will return us full datarow where that string is present.( Correct me if I am wrong)
Once I receive that datarow how can I write inside that row ?
Let me know if I cannot achieve this using select then I use for each Method.


#11

Have you tried this?:

datarow(“Name of the column”) = Your new value ; I’m not sure 100% if that will work when you are in a datarow… That works in for each row, taking datarow as type of argument… but outside of that activity i dont know how it will act


#12

You can write inside the DataRow like this within an Assign Activity,
dtRowArray(0).Item(1) = “Status”, but unfortunately this will be an independent DataRow and won’t be updated in your existing DataTable. You may have to Add this row in your existing or new DataTable.

I don’t see a way to directly update this DataRow into a matched position in your existing datatable. Not sure if there is any such method that does exist which i may not be aware of. :slight_smile:

Thanks,
Rammohan B.


#13

Hi Ram,
Thanks for the advice, then I use for each only.
Once again thank you all.


#14

No bro that will not work outside the for each.