简体   繁体   English

vb.net中的通用搜索框并从多个表中进行检查

[英]Universal searchbox in vb.net & checking from multiple tables

My concept is little unclear. 我的概念还不清楚。 For my site I want to create a searchbox. 对于我的网站,我想创建一个搜索框。 And I will use Autocomplete function to check related keywords from database. 我将使用自动完成功能从数据库中检查相关的关键字。 So while typing matching word will come as suggestion. 因此,在输入匹配词时会提示您。 But I am not sure about how to check it through multiple tables. 但是我不确定如何通过多个表进行检查。 My concept is on health based site so there is different table for each sections like hospitals, doctors, laboratories, chemist etc. I just need guidance how should I do it? 我的概念是在基于健康的网站上进行的,所以每个部分都有不同的表格,例如医院,医生,实验室,化学家等。我只需要指导,应该怎么做?

You can use union queries to return autocomplete data for your textbox. 您可以使用联合查询返回文本框的自动完成数据。 For example, you could write a query that for a search term could do this: 例如,您可以编写一个查询来使搜索字词可以做到这一点:

select hospitals.name as name
from hospitals
where hospitals.name like '%?%'
UNION
select doctors.lastname as name
from doctors
where doctors.lastname like '%?%'
UNION
select laboratories.labname as name
from laboratories
where laboratories.labname like '%?%'
UNION
...

Be careful though: the performance of this could degrade fast, especially for "contains" searches like the example above ( like '%?%' ). 但是请小心:这样做的性能可能会迅速下降,尤其是对于上面示例中的“包含”搜索( like '%?%' )。
A faster query would be a "starts with" which would change the like clause in the query above to like '?%' 更快的查询将是“开始于”,这会将上面查询中的like子句更改为like '?%'

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

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