Reputation: 75
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
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
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