搜索包含在同一文本框中搜索名字和姓氏 [英] Search contains search for firstname and lastname in same textbox
本文介绍了搜索包含在同一文本框中搜索名字和姓氏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在文本框中搜索我的数据库,我想输入名字和姓氏并搜索,我的代码如下:
I am trying to search in my database in a textbox there I want to type firstname and lastname and search , my code looks as following,
using (var db = new knowitCVdbEntities())
{
var employee = (from p in db.EMPLOYEES
where
p.firstname.Contains(TextBoxSearch.Text) &&
p.lastname.Contains(TextBoxSearch.Text)
select p).ToList();
这样做我不能搜索名字和姓氏为什么?
Doing like this I cannot search for firstname and lastname why?
推荐答案
First&最后这两个名字应该包含相同的字符串!?
:)
我想,你想要其中一个包含特定字符串
只需使用Logical OR || 而不是&&
First & last both name should contain same string!?
:)
I think, you want one of them contain specific string
Just use Logical OR || instead of &&
using (var db = new knowitCVdbEntities())
{
var employee = (from p in db.EMPLOYEES
where
p.firstname.Contains(TextBoxSearch.Text) ||
p.lastname.Contains(TextBoxSearch.Text)
select p).ToList();
快乐编码!
:)
Happy Coding!
:)
这篇关于搜索包含在同一文本框中搜索名字和姓氏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文