查询末尾缺少引号分隔符.&;错误在WinCE PDA应用程序

本文关键字:错误 WinCE 应用程序 PDA 分隔符 查询 | 更新日期: 2023-09-27 18:10:24

在我的WinCE PDA应用程序中,我正在将扫描到的条形码值与数据库中的条形码值进行比较,以生成一个表。

我像这样构建查询:

for (int i = 0; i < listBox2.Items.Count; i++)
{
    if (i == 0)
    {
        sb.Append("Select * from ToolsBar where BarcodeValue in (");
    }
    sb.Append("'" + listBox2.Items[i] + "',");
}
sb.Length = sb.Length - 1;
sb.Append(")");

在这里使用:

cmd.CommandText = sb.ToString();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
reader = cmd.ExecuteReader(); // this is where the error came out  "A quotation mark delimiter is missing from the end of the query." 
reader.Close();
SqlCeDataAdapter ad = new SqlCeDataAdapter(sb.ToString(), con);
DataSet ds = new DataSet();
ad.Fill(ds);
dataGrid2.DataSource = ds.Tables[0];
con.Close();
sb.Length = 0;

查询末尾缺少引号分隔符.&;错误在WinCE PDA应用程序

构建查询的替代循环,无需更改字符串长度:

for (int i = 0; i < listBox2.Items.Count; i++)
{
    if (i == 0)
    {
        sb.Append("Select * from ToolsBar where BarcodeValue in (");
        sb.Append("'" + listBox2.Items[i] + "'");
    }
    else
    {
        sb.Append(",'" + listBox2.Items[i] + "'");
    }
}
sb.Append(")");