简体   繁体   English

选择查询中出现错误:条件表达式中的数据类型不匹配

[英]error In select query : Data type mismatch in criteria expression

I am using Access database ,and trying to fetch data of column of DataType Yes/No with value true , but its not working, and giving me following error 我正在使用Access database ,并尝试获取值为true的DataType Yes/No列的数据,但它不起作用,并给我以下错误

Data type mismatch in criteria expression.

below is query 下面是查询

cmd2 = new OleDbCommand("Select TOP " + PageSize + " DoctorID,FirstName&' '&LastName as [Doctor Name],ContactNo_1&' , '&ContactNo_2 as [Contact number],City,Email_ID from Doctor_Master WHERE Display='" + true.ToString() + "' ORDER BY DoctorID", con);

How do I check this Value WHERE Display='" + true.ToString() + "' 我该如何检查此值WHERE Display='" + true.ToString() + "'

You are trying to compare string to a boolean thus the type mismatch. 您正在尝试将stringboolean进行比较,从而将类型不匹配。 So, try removing the single quote from: 因此,尝试从中删除单引号:

WHERE Display=" + true.ToString() + ""

You could also use Yes instead of True like: 您还可以使用Yes代替True,例如:

WHERE Display= Yes"

or again use True 或再次使用True

WHERE Display= True"

and hard coded by the way as Ahmed already suggested. 并按照艾哈迈德(Ahmed)的建议进行硬编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM