2015-12-08 78 views
0

我有一個簡單的選擇查詢其在Access工作正常,但不是在C#代碼 以下是訪問 enter image description here查詢選擇查詢工作正常Access2010,但不是在C#代碼

SELECT FIRST(ItemName) As Item 
from SubmitData 
where ItemName like 'txt_rdo_breaks*' 
and Deleted=false 

下面是它的結果

但在C#代碼它retruns什麼 下面是C#代碼

cmd1.CommandText = "SELECT FIRST(ItemName) As Item from SubmitData where ItemName like 'txt_" + controlPatrs[0] + "*' and Deleted=false"; 
OleDbDataReader reader1 = cmd1.ExecuteReader(System.Data.CommandBehavior.Default); 
while (reader1.Read()) 
{ 
    if (Convert.ToString(reader1["Item"]).Length > 1) 
    { 
      tag += Convert.ToString(reader1["Item"]) + "|txt_" + controlPatrs[0] + "|" + controlPatrs[2] + "||"; 
    } 

    } 
reader1.Close(); 

enter image description here

+0

將'Deleted = false'更改爲'Deleted = 0'。 – Mairaj

+0

FIRST是MS Access獨有的。如果您將其更改爲MAX或其他功能,您會得到結果嗎? – smoore4

+0

@MairajAhmad:還是一樣的 –

回答

0

伊萬Stoev的評論

OleDbProvider query seems to require a different wildcard characters - '%' 

在訪問它*標誌的工作,但在使用OleDbProvider %標誌工作。 所以正確的命令文本是

cmd1.CommandText = "SELECT FIRST(ItemName) As Item from SubmitData where ItemName like 'txt_" + controlPatrs[0] + "%' and Deleted=false"; 
相關問題