DataTable.Select() cannot assign

Hello, I am working with the 1rst assignment of the advanced course from the academy. While trying to use the “DataTable.Select()” to filter the datatable I get the following error:

image

The assign has the following:
System1_DataTableProcessed = System1_DataTable.Select("Type= W15 AND Status= Open ")

Im confused, at first i thought that the “.Select()” method gave a datatable as output, then after receiving the error the first time i tried changing the type of the variable to the right (the “System1_DataTableProcessed”) but even after that i cant make it work properly.

Any help will be very appreciated. Thank you!

Hi.

.Select() returns a 1-dimensional array. If you would like a data table, just add .CopyToDataTable on the end of it. There are times when you do want to use the filtered dataset as an array, though too.

Regards.

3 Likes

@ClaytonM Thank you very much! Sadly, now I have an issue when filtering because it doesn’t. The datatable after filtering looks like in the image and it contains rows with elements of “WI2” Type.

image

Do you know how to make it filter? Thanks again!

Hey.

I think it skipped your filter cause of an error in your filter code. I think you need single quotes around the values.

System1_DataTableProcessed = System1_DataTable.Select("Type= 'W15' AND Status= 'Open' ")

Try that.

I tried but the output is the same:

image

it still shows rows with other types.

I had tested the code on my end and it worked, so is there a way you can upload a sample workflow where it doesn’t work? Then, I can examine it.

Sure:

Calculate_Client_Security_Hash.zip (524.4 KB)

thank you very much!

lol, hey can you tell me where you have it filtering the data table? I found where you are extracting the data table (I think), but I don’t see anywhere you are filtering it.

Sorry, I have it on the main flow, inside the init state machine

Found it.

Looks like you did it correctly, although I was not able to run it.
I assume you tried both the Filter activity and the Assign.

You can also change your Assign to use this code instead which is usually the syntax I use:
System1_DataTable.AsEnumerable.Where(Function(r) r("Type").ToString.Trim.ToUpper = "WI5" AND r("Status").ToString.Trim.ToUpper = "OPEN").CopyToDataTable

@ClaytonM thank you for your patience and tips, i tried with the code you provided and it didn’t work.After debbuging I received the following message:

I tried to clear the variables used as databases and when i reach the “Clear Datatable” activity it says the same. Is there a way to initialize the datatables, or is this even needed?

That errors tells me you are using a variable with no value in the activity “Assign”. Note: always rename your activities so you know the exact activity that failed.

I would verify that you have no empty values being used in the Assign activity that failed.

The DataTable gets initialized at the start of its scope, so you don’t need to clear it or anything. If you do need to initialize it in some cases, then you can also use an Assign with new System.Data.DataTable()

You are right! When running the main flow the variables that will hold datatables are initialized.

But, after executing the “System1_Extract_Data” flow this variables got “Null” as value. My error was not assigning the value of the extracted datatable to the argument invoked from the “System1_Extract_Data

image

out_System1_DataTable = System1_DataTable

with out_System1_DataTable as the output argument and System1_DataTable as the value.

Its a very basic mistake and I’m a little embarrassed but I really appreciate your time and effort helping me, it worked!

Thank you very much @ClaytonM!. Also, as the the topic of the post was DataTable.Select() cannot assign ill mark your previous post

as the answer.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.