Problem with select on datatable

Hello,

I have a problem with the select function on my datatable. A field on that tabel is called 'Quay', and I want to filter on it.
So, I enter the following code:

        lsFilter = "Quay = " + lsQuay
        filterResult = dtOrders.Select(lsFilter)

When I run this code, I get the error 'Cannot find column [QA01]'. My problem is: QA01 is the value in lsQuay, not the column.
Any Idea how I can solve this.

This code does work file:

        lsFilter = "[Location code] = " + lsLocation
        filterResult = dtOrders.Select(lsFilter)

I cannot see a difference between the 2 code snippets. I tried the filter "[Quay] = " + lsQuay, but that doesn't work either.

Kind regards
ACAEAsked:
Who is Participating?
 
TimCotteeConnect With a Mentor Head of Software ServicesCommented:
Hello ACAE,

Location code is presumably numeric!

What you need is this:

lsFilter = "Quay = '" & lsQuay & "'"

Or

lsFilter = String.Format("Quay = '{0}'",lsQuay)

Or

lsFilter = String.Concat("Quay = '",lsQuay,"'")

Which all provide the correct string but in different ways.

Regards,

TimCottee
0
 
ACAEAuthor Commented:
Damn, I feel kind of stupid now. Location is not a numeric fields, but the content is numeric.

Thx for your help, it works fine now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.