我有一个简单的Select Query,它在Access中运行良好,但在C#代码中运行不正常 这是查询
SELECT FIRST(ItemName) As Item
from SubmitData
where ItemName like 'txt_rdo_breaks*'
and Deleted=false
但是在C#代码中它什么都没有 这是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();
答案 0 :(得分:0)
关注 Ivan Stoev的评论
OleDbProvider query seems to require a different wildcard characters - '%'
在Access中使用*
符号,但使用OleDbProvider %
符号时有效。
所以正确的命令文本是
cmd1.CommandText = "SELECT FIRST(ItemName) As Item from SubmitData where ItemName like 'txt_" + controlPatrs[0] + "%' and Deleted=false";