Asp.net 如何选择具有多个类别的产品
根据我的问题标题,我有如下Access数据库结构: 类别Asp.net 如何选择具有多个类别的产品,asp.net,ms-access,Asp.net,Ms Access,根据我的问题标题,我有如下Access数据库结构: 类别 categoryid categoryname 1 one 2 two 3 three categoryid categoryname 1 one 2 two 3 three 产品表: productid productname categories 1 one
categoryid categoryname
1 one
2 two
3 three
categoryid categoryname
1 one
2 two
3 three
产品表:
productid productname categories
1 one 1,2,3
2 two 3
3 three 1,2
当我的categoryid为1时我不知道如何选择具有多个分类的产品。因为当我在操作符中使用时,我得到了一些错误
Select * from product where categories In (categodyid) because cannot compare a collection with one value.
我被困在这里了!请帮帮我!谢谢 这是一种典型的亲子一对多关系。您需要一个
[ProductCategory]
表来将给定产品与多个类别关联:
productid categoryid
1 1
1 2
1 3
2 3
3 1
3 2
首先,您的表没有规范化。查看产品表中的“类别”列。每个单元格应该只有一个值。通过允许多个值,您可能会遇到各种问题,包括更新/插入异常和您现在看到的情况。您还使得执行选择和其他操作变得非常困难。相反,请考虑使用以下示例规范化您的表: 类别
categoryid categoryname
1 one
2 two
3 three
categoryid categoryname
1 one
2 two
3 three
产品
ProdductId ProductName
4 prod1
5 prod2
6 prod 3
类别产品
CategoryId ProductId
1 3
1 4
2 3
第三个表充当了补救多对多模式的方法。如果您对如何操作或如何使用有任何疑问,请告诉我。非常感谢您的回复\