首页 >> 大全

查询功能——“模糊查询”

2023-10-14 大全 26 作者:考证青年

撰写时间:2019年7月26日

在一些实际项目中——模糊查询这个功能往往能发挥很大的作用,而且模糊查询在我们手机、电脑上用来查找信息用得最多的一种搜索功能。那么它主要就是用于一些与“数据”相关的信息,通过它可快速查找到我们想要的信息;它通常是用关键字模糊查找,所谓关键字就是关区信息中所包含的字符等等。

所谓“模糊查询”,就是利用部分参数或者是字段查找到一些相关数据的方式。比如说按姓名查询拿到某条用户信息,仅指定姓名的某个部分,如姓或者名字中的某个字或者它们的组合,都可以找出与他们相关的一些信息数据。那么它的主要用来在我们已知信息少的情况下尽可能的找出我们所需要的数据信息。查询关区信息中的某条信息我们怎么做呢?首先,先获取它的查询条件:我呢是根据关区的编码来查询关区的信息,然后呢就重载表格的数据,给他条件Where这是页面上的。

下面我们一起来看一下这个例子:

控制器那边的就是要查询这个关区的所有的信息,多表的就要联表查询其他的表里面的信息(Join tb in +表名 on tb点那个表ID tb+ID)这样就可以联到其他的表和他的一些相关的信息和数据,如果想要倒序那就+tb+主表的ID 最后加一个倒序,如下图所示:

查询的完整代码如下:

public ActionResult SelectDistrict(LayuiTablePage layuiTablePage, string ZoneCoding)
{
List listDistrict = (from tbDistrict in myModel.B_District
join tbCustoms in myModel.B_Custom on tbDistrict.CustomsID equals tbCustoms.CustomsID
join tbDoorPoint in myModel.B_DoorPoint on tbDistrict.DoorPointID equals tbDoorPoint.DoorPointID
orderby tbDistrict.DistrictID descending
select new DistrictVo{
ZoneCoding = tbDistrict.ZoneCoding,//关区编码
DistrictID = tbDistrict.DistrictID,//关区IDs
DoorPointID = tbDistrict.DoorPointID,//门点ID
CustomsID = tbDistrict.CustomsID,//海关ID
CustomsName = tbCustoms.CustomsName,//海关名称
ZoneEnglishName = tbDistrict.ZoneEnglishName,//英文名称
DoorPointName = tbDoorPoint.DoorPointName,//门点名称
Describe = tbDistrict.Describe,//描述
Location = tbDistrict.Location,//地址
ZoneInvalidation = tbDistrict.ZoneInvalidation,//是否启用
Website = tbDistrict.Website,//网址
ClosingTime1 = tbDistrict.ClosingTime.ToString(),//下班时间*/
Workday2 = tbDistrict.Workday.ToString(),//上班时间
Postcode = tbDistrict.Postcode,//邮编
Fax = tbDistrict.Fax,//传真
Email = tbDistrict.Email,//邮件
LXman = tbDistrict.LXman,//联系人
Telephone = tbDistrict.Telephone,//电话
MobilePhone = tbDistrict.MobilePhone//手机
}).ToList();
//模糊查询
if (!string.IsNullOrEmpty(ZoneCoding)){
listDistrict = listDistrict.Where(m => m.ZoneCoding.Contains(ZoneCoding)).ToList();
}
//计算数据总条数
int totalRow = listDistrict.Count();
//提取数据
List bdDistrict = listDistrict
.Skip(layuiTablePage.GetStartIndex())
.Take(layuiTablePage.limit)
.ToList();
//实例化
LayuiTableData layuiTableData = new LayuiTableData();
layuiTableData.count = totalRow;
layuiTableData.data = bdDistrict;
return Json(layuiTableData, JsonRequestBehavior.AllowGet);
}

模糊查询对应的是什么查询_查询模糊功能的软件_

下面的这句代码是最主要的模糊查询

//模糊查询
if (!string.IsNullOrEmpty(ZoneCoding)){
listDistrict = listDistrict.Where(m => m.ZoneCoding.Contains(ZoneCoding)).ToList();}

效果图如下图所示:

我是根据关区的编码来查询关区的信息的,下面我们可以看到有关于“J”的编码的关区信息查询得到的信息有两条,那么以上的就是我写的模糊查询。当然了我们也可以用模糊查询来查其他我们需要的信息。

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了