我正在尝试搜索员工记录,但收到此错误消息:
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/