views:

1247

answers:

1

I have populated a datatable from a SQL stored procedure and need to do further filtering on the datatable. The datatable holds data that is returned from the SQL DB as varbinary and is stored in the datatable as a byte array. I am attempting to pass TheData!Hash which is also a byte array.

When I need to filter the datatable I have use the following:

Dim sQuery0 As String = "Hash=" & TheData!Hash
Dim ResultRows As DataRow() = dt.Select(sQuery0)

I understand that the TheData!Hash is a byte array and cannot be converted to a string in this way but how on earth do I pass the byte array in the Select filter expression?

+1  A: 

I don't believe you'll get this to work. What's the type of TheData!Hash? Byte()? Then if you did this comparison in code, it would be a reference comparison in any case.

Take a look at LINQ to DataSet. You'll find it much more flexible than the Select method, which is from .NET 1.0.

John Saunders
JohnYes that's the solution. I'd not used LINQ before but it works like a charm.Thanks
However...When I run the following statement I get no rows returned: Dim Query0 = _ From Table1 In dt.AsEnumerable _ Where Table1.Field(Of System.Byte())("Hash") Is TheData!Hash _ Select Table1Running a different query using string based data returns rows.Any ideas?
Like I said, you're comparing two references for equality. They're obviously not the same. You need a _value_ comparison that compares each byte of each array after checking that they're the same length.
John Saunders
Thanks John, I think i get the idea now.