Sunday, April 3, 2011

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.

From stackoverflow
  • 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.

    NastyNateDoggy : Appreciate the answer :-)

0 comments:

Post a Comment