Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bit 'And' Operation on Datatable Integer Column

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top