NastyNateDoggy
NastyNateDoggy

Reputation: 292

C# Sql Compact text query on binary column

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.

Upvotes: 1

Views: 1115

Answers (1)

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422280

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.

Upvotes: 3

Related Questions