×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Bit 'And' Operation on Datatable Integer Column

Bit 'And' Operation on Datatable Integer Column

Bit 'And' Operation on Datatable Integer Column

(OP)
Testing some code to set a row filter on a table with an integer column using the bit "And" operator.
Can't seem to get it to work.
Sadly I think I ran across this a while ago and don't remember how I got around it.

CODE

Dim myTable As New DataTable
 myTable.Columns.Add("Desc", Type.GetType("System.String"))
 myTable.Columns.Add("KeyNbr", Type.GetType("System.Int32"))

 myTable.Rows.Add("Open", 2)
 myTable.Rows.Add("Hold", 4)
 myTable.Rows.Add("Covered", 8)
 myTable.Rows.Add("Complete", 16)

 Dim Compare As Integer = 10

 myTable.DefaultView.RowFilter = "(KeyNbr And " & Compare.ToString & ") > 0" 
I've tried changing the Int32 to Int16, but did not help.
I get an error something like the following.
".net cannot perform 'and' operation on system.int32 and system.int32"
Must be something simple I'm missing.
Can I not use an integer as large as Int32?

Auguy
Sylvania/Toledo Ohio

RE: Bit 'And' Operation on Datatable Integer Column

(OP)
On further investigation this is not possible.
I can use the following to get around this because these are really small tables I'm working with.

CODE

myTable.Columns.Add("Desc", Type.GetType("System.String"))
 myTable.Columns.Add("KeyNbr", Type.GetType("System.Int16"))
 myTable.Columns.Add("Available", Type.GetType("System.Int16"))

 myTable.Rows.Add("Open", 2, 0)
 myTable.Rows.Add("Hold", 4, 0)
 myTable.Rows.Add("Covered", 8, 0)
 myTable.Rows.Add("Dispatch", 16, 0)

 ' Don't forget to clear Available if doing this more than once and reset the rowfilter
 Dim Cmp As System.Int16 = 20
 myTable.DefaultView.RowFilter = "" 
For Each dr As DataRow In myTable.Rows
   If (CInt(dr.Item("KeyNbr")) And Cmp) > 0 Then
     dr.Item("Available") = 1
   Else
     dr.Item("Available") = 0
   End If
 Next

 myTable.DefaultView.RowFilter = "Available = 1" 

Auguy
Sylvania/Toledo Ohio

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close