在asp.net中搜索我的电子商务数据库 [英] Search my ecommerce database in asp.net

查看:92
本文介绍了在asp.net中搜索我的电子商务数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我的电子商务网站中,我必须集成一个产品搜索模块,搜索应该按标题,制造商和类别进行.所以我的问题是:使用"like"查询搜索产品就足够了吗?这意味着如果用户按类别进行搜索,我将转到类别表并进行类似的查询并获得结果.

Hi all ,

In my eCommerce website i have to integrate a search module for products,and the search should be by title,manufacturer,and category.So my question is: Is searching for products using the "like" query is enough ? which means if the user searched by category, i go to the category tables and make the like query and get the results.

Thanks in advance.

推荐答案

按标题和按制造商进行的产品搜索与按类别进行的产品搜索不同;因为我假设您将有一个将从数据库中填充的类别列表(当然,更不用说每个类别都将具有与其关联的ID),并且Title和Manufacturer可以与以下相同,也可以是免费的文本字段(例如文本框)进行搜索.

假设类别是一个列表,标题和制造商是自由文本字段,则可以执行以下操作

前端:

从列表中选择一个类别
输入标题
类型制造商

后端
该查询将是这样的;

Product search By Title and By Manufacture is different from Product search by Categories; because I assume that you would have a list of categories which will be populated from the database (of course not to mention that each category would have an ID associated with it) and Title and Manufacturer can be either the same as follows or be a free text field (like text boxes) to search.

Assuming categories is a list, Title and Manufacturer are free text field, you can do the following

Front End:

Select a category from the list
Type title
Type Manufacturer

Back End
The query would be something like this;

select *
from  dbo.Products 
where categoryID = coalesce((ID from the front end), categoryID)
and   title like ''%'' + @title + ''%''
and   manufacturer like ''%'' + @manufac + ''%''



如果未提供类别ID,则使用Coalesce关键字,它仍将返回所有相关结果.

希望这会有所帮助
快乐编码:)



coalesce keyword is used if the category id is not supplied, it still returns all relevant results.

Hope this helps
Happy Coding :)


这篇关于在asp.net中搜索我的电子商务数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆