Problem with table.select(criteria)

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I'm trying to filter a table using the select method like this:

Note: dsSessionMngr is a strongly typed dataset
CustRef is a string column in the dataset's table named CartDetails

Dim tb As dsSessionMngr.CartDetailsDataTable = Me.dsSM.Tables("CartDetails")
Dim crit as string = "1234 - Blue" '1234 is not a number but is just part
of a alphanumeric value
Dim foundRows() As dsSessionMngr.CartDetailsRow = tb.Select("CustRef = " &
crit )

When this 3rd line executes I get an exception saying:
Cannot find column [Blue].

It thinks I'm taking a numeric value of 1234 and subtracting the value in a
column called 'Blue'. So I tried wrapping the criteria in single quotes and
double quotes similar to what you might do in sql server for a varchar
parameter variable. the double quote bombed with some sort of syntax error,
but single quote gave me an exception saying:
You can not use "=" when comparing datatypes string and int32.

This is because the value in the dataset was a string value of "1234" and
the criteria was " '1234 - Blue' ".

ADO is trying to be too smart and figure things out for itself. The column
is a string data type and I'm comparing it with a string value for the
criteria which is what I'm supposed to do.

How can I get this to work?

Thanks.
 
Try replacing line 3 with:

Dim foundRows() As dsSessionMngr.CartDetailsRow = tb.Select("CustRef = '" &
crit & "'")
 
Sorry for the short answer previously. I realize that you said you tried
putting the value in single quotes but wasn't sure of your method (ie: like
I posted or in the string variable itself). The result should be the same
but it's worth a shot.

If the method posted still doesn't work could you post some more code
regarding your strongly typed data set?

EijiTek said:
Try replacing line 3 with:

Dim foundRows() As dsSessionMngr.CartDetailsRow = tb.Select("CustRef = '" &
crit & "'")


moondaddy said:
I'm trying to filter a table using the select method like this:

Note: dsSessionMngr is a strongly typed dataset
CustRef is a string column in the dataset's table named CartDetails

Dim tb As dsSessionMngr.CartDetailsDataTable = Me.dsSM.Tables("CartDetails")
Dim crit as string = "1234 - Blue" '1234 is not a number but is just part
of a alphanumeric value
Dim foundRows() As dsSessionMngr.CartDetailsRow = tb.Select("CustRef = " &
crit )

When this 3rd line executes I get an exception saying:
Cannot find column [Blue].

It thinks I'm taking a numeric value of 1234 and subtracting the value
in
 
Thanks. I thought I had tried that when I tested the double quotes and then
the single quotes, but I must have messed up the syntax in the test as it
works now when I tried it again.

--
(e-mail address removed)
EijiTek said:
Try replacing line 3 with:

Dim foundRows() As dsSessionMngr.CartDetailsRow = tb.Select("CustRef = '" &
crit & "'")


moondaddy said:
I'm trying to filter a table using the select method like this:

Note: dsSessionMngr is a strongly typed dataset
CustRef is a string column in the dataset's table named CartDetails

Dim tb As dsSessionMngr.CartDetailsDataTable = Me.dsSM.Tables("CartDetails")
Dim crit as string = "1234 - Blue" '1234 is not a number but is just part
of a alphanumeric value
Dim foundRows() As dsSessionMngr.CartDetailsRow = tb.Select("CustRef = " &
crit )

When this 3rd line executes I get an exception saying:
Cannot find column [Blue].

It thinks I'm taking a numeric value of 1234 and subtracting the value
in
 
Back
Top