Skipper Geffen
Skipper Geffen

Reputation: 75

Sql Compact edition - simple select statement doesn't work

I have this really simple trouble I can't seem to overcome.

I'm trying to execute this code lines with sql ce :

SqlCeCommand comSelect = new SqlCeCommand("SELECT * FROM Items WHERE barcode = '@barcode'", conn);
comSelect.Parameters.Add(new SqlCeParameter("barcode", System.Data.SqlDbType.NVarChar, 100)).Value = barC;

For some weird reason - it always comes back as empty- i.e not results found. If I put the parameter value by myself in the query string, like so:

SELECT * FROM Items WHERE barcode = '123ABC'

then it works perfect. I will add that the column IS a NVarChar.

Any idea of why this isn't working?

Upvotes: 0

Views: 1866

Answers (2)

4b0
4b0

Reputation: 22323

try:

new SqlCeCommand("SELECT * FROM Items WHERE barcode = @barcode", conn);
comSelect.Parameters.Add(new SqlCeParameter("@barcode", System.Data.SqlDbType.NVarChar, 100)).Value = barC;

Upvotes: 6

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181340

Try using this:

"SELECT * FROM Items WHERE barcode = @barcode"

Instead of what you have. Please do note the lack of quotes in @barcode.

Upvotes: 2

Related Questions