c# - OR LIKE sql查询 bool 错误

标签 c# mysql asp.net sql sql-server

我正在尝试搜索员工记录,但收到此错误消息:

An expression of non-boolean type specified in a context where a condition is expected, near 'OR'.

这是我正在使用的代码:

sConn = new SqlConnection(sStr);

daEmp2 = new SqlDataAdapter("
SELECT employee.*,
       department.Department
FROM tblEmployee employee
INNER JOIN tblDepartment department ON employee.DeptID=department.DeptID
WHERE Lname OR Fname LIKE '%" + txtName.Text + "%'
", sConn);

dsEmp2 = new DataSet();
daEmp2.Fill(dsEmp2, "tblEmployee");

我的查询有问题吗?

最佳答案

or 连接 SQL 中的 bool 条件——求值为 true 或 false 的条件。

你需要重复条件:

Lname LIKE '%" + txtName.Text + "%'" OR Fname LIKE '%" + txtName.Text + "%'"

关于c# - OR LIKE sql查询 bool 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20025496/

相关文章:

c# - 在 C# 中是否有等效于 JavaScript parseInt 的东西?

php - 我可以一次将一个 mysql 函数转换为 PDO 吗?

c# - MVC 一次性 Controller

c# - 在 Response.Redirect 上更改域

c# - Entity Framework 自定义数据类型映射

c# - 通过 C# 代码隐藏将字符串传递给 .ASPX 中的 SQL

c# - 从 AR 相机截屏后更新 Android Gallery?

PHP + Mysql : How to insert data having , "'(分号,单引号+双引号)

mysql - date String "08th August 2017"到mysql中的日期转换

c# - 如何逐步显示 div 标签