Home All Groups Group Topic Archive Search About

Bitwise comparison in RowFilter expressions

Author
7 Oct 2006 11:51 AM
Mark Rae
Hi,

This isn't *specifically* an ASP.NET question, so I've also posted it in the
ADO.NET group - however, it's not too far off-topic...

Imagine a SQL Server 2005 database with a table with an int column used for
bitwise data - you know the sort of thing... 0, 1, 2, 4, 8, 16 etc

intBitwise    strName
----------------------
512            Mark
512            Juan
514            Ken
512            Peter
512            Marina

In T-SQL, the following query:

SELECT * FROM tblBitwise WHERE intBitwise & 2 = 2

returns, of course, only the third record from the table.

However, in C#, the following doesn't work:

<DataSet>.Tables[0].DefaultView.RowFilter = "intBitwise & 2 = 2";

The error message is: "The expression contains unsupported operator '&'.

Fair enough - there are loads of other ways to achieve the desired result.
However, I am now curious about RowFilter expressions and bitwise
operators...

A quick trawl through Google returns sites which say that bitwise operators
aren't supported in RowFilter expressions:
https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=262068&SiteID=1

And others which imply that they are:
http://66.102.9.104/search?q=cache:i234VsP-oA8J:www.oreilly.com/catalog/adonetian/chapter/ch12.pdf+DefaultView+RowFilter+bitwise&hl=en&gl=uk&ct=clnk&cd=2

So, can anyone please confirm whether bitwise operators are or are not
supported in RowFilter expressions...?

Any assistance gratefully received.

Mark

Author
7 Oct 2006 1:41 PM
Miha Markic [MVP C#]
I don't think bitwise ops are supported as DataColumn.Expression (used for
filters) isn't exactly too rich.
OTOH you could create additional column in datatable, compute manually
bitwise results and store them in this column. Then you can filter on it.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Mark Rae" <mark@markNOSPAMrae.com> wrote in message
news:OEDBpbg6GHA.200@TK2MSFTNGP05.phx.gbl...
> Hi,
>
> This isn't *specifically* an ASP.NET question, so I've also posted it in
> the ADO.NET group - however, it's not too far off-topic...
>
> Imagine a SQL Server 2005 database with a table with an int column used
> for bitwise data - you know the sort of thing... 0, 1, 2, 4, 8, 16 etc
>
> intBitwise    strName
> ----------------------
> 512            Mark
> 512            Juan
> 514            Ken
> 512            Peter
> 512            Marina
>
> In T-SQL, the following query:
>
> SELECT * FROM tblBitwise WHERE intBitwise & 2 = 2
>
> returns, of course, only the third record from the table.
>
> However, in C#, the following doesn't work:
>
> <DataSet>.Tables[0].DefaultView.RowFilter = "intBitwise & 2 = 2";
>
> The error message is: "The expression contains unsupported operator '&'.
>
> Fair enough - there are loads of other ways to achieve the desired result.
> However, I am now curious about RowFilter expressions and bitwise
> operators...
>
> A quick trawl through Google returns sites which say that bitwise
> operators aren't supported in RowFilter expressions:
> https://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=262068&SiteID=1
>
> And others which imply that they are:
> http://66.102.9.104/search?q=cache:i234VsP-oA8J:www.oreilly.com/catalog/adonetian/chapter/ch12.pdf+DefaultView+RowFilter+bitwise&hl=en&gl=uk&ct=clnk&cd=2
>
> So, can anyone please confirm whether bitwise operators are or are not
> supported in RowFilter expressions...?
>
> Any assistance gratefully received.
>
> Mark
>
Author
7 Oct 2006 2:07 PM
Mark Rae
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:%23flHEZh6GHA.348@TK2MSFTNGP02.phx.gbl...

>I don't think bitwise ops are supported as DataColumn.Expression (used for
>filters) isn't exactly too rich.

OK.

> OTOH you could create additional column in datatable, compute manually
> bitwise results and store them in this column. Then you can filter on it.

Yes I know...

AddThis Social Bookmark Button