I have a Windows Mobile Application that uses MSFT sync framework and is querying a sql database.
Here is the code:
private void buttonStart_Click(object sender, EventArgs e)
{
using (SqlCeConnection conn = new SqlCeConnection(
("Data Source=" + (Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), "Barcode.sdf") + ";Max Database Size=2047"))))
{
// Connect to the local database
conn.Open();
using (SqlCeCommand cmd = conn.CreateCommand())
{
SqlCeParameter param = new SqlCeParameter();
param.ParameterName = "@Barcode";
param.DbType = DbType.String;
param.Value = textBarcode.Text.Trim();
// SELECT rows
cmd.CommandText = "SELECT Location, Reading FROM Main WHERE Barcode LIKE @Barcode";
cmd.Parameters.Add(param);
DataTable data = new DataTable();
using (SqlCeDataReader reader = cmd.ExecuteReader())
{
data.Load(reader);
this.dataGrid1.DataSource = data;
}
}
}
}
Here is the table:

So when I change the query to this:
cmd.CommandText = "SELECT Location, Reading FROM Main WHERE Barcode LIKE 'NGM0001'";
It returns the correct results. But when NGM0001 is in textBarcode and entered no results are returned. Leading me to believe it has to be a problem with the parameter. I had the same code segment working in another solution so I’m not sure what is going wrong.
Also all of the db fields are nvarchar(50) type.
Thanks for your help.
The above code is correct. I recompiled and tested the application again and it works fine. I am not sure what the problem was.