Select method not working when column name is a variable

Hello guys. I’m trying to use the select method and it works in the following format:

in_dtDataCID.Select(“Department = '”+row(“Department”).tostring +"’").CopyToDataTable

As i will use this method in other processes (Subdepartments and Functions) i want to create a variable to replace the Department column and take the value of Subdepartments and also Functions:

new variable: in_Type

in_dtDataCID.Select("’" +in_Type+ “’ = '”+row(in_type).tostring +"’").CopyToDataTable

but it throws error that no rows found.

I’m guessing the problem is with this part here: ‘"+row(in_type).tostring +"’.

Much appreciated for your help!

You have single quotes around in_Type so the comparison being done is 'type'=… instead of type=
If you remove those single quotes you should be fine.

I’m afraid i don’t see where i should put the single quotes. Can you write it down? much appreciated

Use this instead:
in_dtDataCID.Select(in_Type+ “ = '”+row(in_type).tostring +"’").CopyToDataTable

1 Like

this works fine:

in_dtDataCID.Select("" +in_Type+ " = ‘"+row(in_type).tostring+"’").CopyToDataTable

Many thanks @DanielMitchell for the solution!

1 Like

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