2014-09-22 40 views
0

我目前正在製作一個指南工具。我連接到我的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個多小時......

回答

0

我想你已經錯過了第一和最後一個字符串分隔符

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

0

看起來你可能會錯過你的查詢字符串中的第一個單引號。

WHERE a_item_0 ='「+ textBox21.Text +」'

相關問題