C# Sql Compact text query on binary column
-
06-07-2019 - |
Question
I was wondering if anyone knew how to compile a text query for sql compact that goes like this :
command.CommandText = "SELECT * FROM tableName WHERE id = binary_Data"
The id column is a 32 byte binary column that is indexed and "binary_Data" is the binary data to compare to, but I am not sure how to get a "binary_Data" into the text query so sql can compare it.
Solution
The best way is to use parameters:
command.CommandText = "SELECT * FROM TableName WHERE id = @binary_data";
command.Parameters.AddWithValue("@binary_data", byteArray);
Alternatively, you could manually build a hex string prefixed with 0x
to create a binary literal to append to the query but it's not recommended.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow