1

私の 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;
4

1 に答える 1

1

文字列の長さを変更する必要をなくすクエリを作成するための代替ループ:

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(")");
于 2015-08-31T04:18:26.373 に答える