datatable.select problem

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

Hi, I use datatable.select to select row in a table in a dataset. I use an
ampersand in the selectstring and get an error that it is unsupported. The
statement works fine in the query analyzer of enterprise manager.
select is like: '1 & val2'
I use the & to have a binary AND comparison=to check if bit 0 of val2 is
set.
Do I make a mistake? Is there a workaround?
Thanks
Frank
 
The syntax for a DataTable.Select criteria is the same as for the
DataColumn.Expression property and is detailed under that heading.

My interpretation is that there is a boolean AND operator but bitwise
operators are not supported.
 
Stephany, thanks for a very fast answer. I will solve it with a function in
the sqlserver db.
Frank
 
Stephany,I interpreted the select command wrong. After reading the doc about
the expression. A sqlserver function of course does not solve the problem.
I have indeed need bitwise comparison and I can't find something about that.
Frank
 
Frank,

Not that I ever tried that, however in your case would I try to add an extra
column using a bitwise expression and than use the Select to test that
column.

I hope this helps,

Cor
 
From the context of your original post, I assume that val2 is an integral
type.

Try "... (val2 % 2 = 1)" for IsBit0Set and "... (val2 % 2 = 0)" for
IsBit0Reset

If bit0 is set then the value is always odd so modulus 2 will always give a
result of 1.

If the result os zero then the value is even therefore bit0 is reset.

The modulus (%) operator is specificailly listed in the
DataColumn.Expression details that I referred you to earlier.
 
Great idea!!!!
Thanks again
Frank

Stephany Young said:
From the context of your original post, I assume that val2 is an integral
type.

Try "... (val2 % 2 = 1)" for IsBit0Set and "... (val2 % 2 = 0)" for
IsBit0Reset

If bit0 is set then the value is always odd so modulus 2 will always give
a result of 1.

If the result os zero then the value is even therefore bit0 is reset.

The modulus (%) operator is specificailly listed in the
DataColumn.Expression details that I referred you to earlier.
 
No, thats still not the solution. If an int contains 3 (bit 0 and 1 set)
then mod does not give the correct answer. I will have to resort to columns
with the respective bitvalues in them.
Frank
 
Que? What math school did you go to?

3 is both bit1 and bit0 set - (11) - and, for an integer, 3 mod 2 = 1 in
anybody's language.
 
yesyes, but the mod function gives back the wrong answer.
Consider: bit 0 and 2 set = 5
5 mod 2 = 1
bit 0,1 and 2 set = 7
7 mod 2 = 1
Twice a mod not equal 0
and bit 1 is set differently. Frank
 
Back
Top