Ole db查询错误缺少运算符

问题描述:

我目前正在制作一个指南工具。我连接到我的accdb文件,所有工作正常。Ole db查询错误缺少运算符

现在我想要wo选择掉物品XY的怪物的名字。

该怪物有19个drop字段,namen从a_item_0到a_item_19。

我的查询是:

string query = "SELECT a_name FROM waffen WHERE a_item_0= " 
    + textBox21.Text + "' OR a_item_1= '" + textBox21.Text 
    + "' OR a_item_2= '" + textBox21.Text + "' OR a_item_3 = '" 
    + textBox21.Text + "' OR a_item_4= '" + textBox21.Text 
    + "' OR a_item_5= '" + textBox21.Text + "' OR a_item_6= '" 
    + textBox21.Text + "' OR a_item_7 = '" 
    + textBox21.Text + "' OR a_item_8 = '" + textBox21.Text 
    + "' OR a_item_9 = '" + textBox21.Text + "' OR a_item_10 = '" 
    + textBox21.Text + "' OR a_item_11 = '" + textBox21.Text 
    + "' OR a_item_12 = '" + textBox21.Text + "' OR a_item_13 = '" 
    + textBox21.Text + "' OR a_item_14 = '" + textBox21.Text 
    + "' OR a_item_15 = '" + textBox21.Text + "' OR a_item_16 = '" 
    + textBox21.Text + "' OR a_item_17 = '" + textBox21.Text + "' OR a_item_18 = '" 
    + textBox21.Text + "' OR a_item_19 = '" + textBox21.Text + ";"; 

也许有人看到的错误,我看现在2个多小时......

我想你已经错过了第一和最后一个字符串分隔符

string query = "SELECT a_name FROM waffen WHERE a_item_0= '" + textBox21.Text 
    + "' OR a_item_1= '" + textBox21.Text + "' OR a_item_2= '" + textBox21.Text 
    + "' OR a_item_3 = '" + textBox21.Text + "' OR a_item_4= '" + textBox21.Text 
    + "' OR a_item_5= '" + textBox21.Text + "' OR a_item_6= '" + textBox21.Text 
    + "' OR a_item_7 = '" + textBox21.Text + "' OR a_item_8 = '" + textBox21.Text 
    + "' OR a_item_9 = '" + textBox21.Text + "' OR a_item_10 = '" + textBox21.Text 
    + "' OR a_item_11 = '" + textBox21.Text + "' OR a_item_12 = '" + textBox21.Text 
    + "' OR a_item_13 = '" + textBox21.Text + "' OR a_item_14 = '" + textBox21.Text 
    + "' OR a_item_15 = '" + textBox21.Text + "' OR a_item_16 = '" + textBox21.Text 
    + "' OR a_item_17 = '" + textBox21.Text + "' OR a_item_18 = '" + textBox21.Text 
    + "' OR a_item_19 = '" + textBox21.Text + "';"; 
+0

谢谢曼!工作完美! – ZaTii 2014-09-22 17:01:20

+0

非常欢迎...新鲜的眼睛总是有帮助 – dav1dsm1th 2014-09-22 17:01:56

看起来你可能会错过你的查询字符串中的第一个单引号。

WHERE a_item_0 ='“+ textBox21.Text +”'