电子商务ASP网 - 在2个表之间查询SQL [英] E-commerce ASP net - query SQL between 2 tables

查看:58
本文介绍了电子商务ASP网 - 在2个表之间查询SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在开发一个电子商务网站,但我有这个问题:如何在我的数据库的表之间带参数?

让我解释一下,我有一个页面,你点击购买一个项目,然后将其添加到购物车(另一个数据库表),但unitl现在我只通过导航网址传递id并使用request.querystring将其带入页面加载。

如何用物品,价格和数量的名称填写购物车?



非常感谢你。



我的尝试:



[已删除]

Hi to all, i ' m developing a E-Commerce web site, but i have problem with this : how can i bring parameters between tables of my db ?
Let me explain better, i have a page where you click buy an item, and then add it to Shopping cart (another db table) , but unitl now i pass only the id through navigation url and take it in page load with request.querystring.
How can i complete the table Shopping Cart with Name of the Item, Price and Quantity ?

Thank you so much.

What I have tried:

[removed]

推荐答案

通常你只存储ID,每当你想要显示basked时,你就会在你的Product表上加入你的Basket表,有效地创建一个包含两个表中所有字段的虚拟表,所以您现在可以访问产品名称等



Normally you would only store the ID and whenever you wanted to show the basked you would JOIN your Basket table on your Product table on the ID, effectively creating a virtual table that has all the fields from both tables, so you can now access the product name etc

SELECT * FROM Basket B JOIN Product P on B.ProductID = P.ID





但是对于购物篮,您可能希望将价格等内容复制到购物篮表中。因此,当它被添加到篮子商店时,产品ID也会存储价格。这样做的原因是价格变化。如果我把它加到我的购物篮中是10英镑并且价格发生了变化,那么它仍然应该在我的购物篮中列为10英镑,因为当他们向顾客添加一些东西时,他们正在与他们签订合同。以该价格购买该商品。



因此,为了展示您的购物篮,您仍然会加入,但产品名称,描述等将来自产品表(P .Name,P.Description在上面的查询中),但你会得到篮子表(B.Price)的价格。



However for a basket you might want to copy things like the price across into your Basket table. So when it is added to the basket store the product ID but also store the price. The reason for doing this is in case the price changes. If it was "£10" when I added it to my basket and the price changes it should still be listed as "£10" in my basket as you are making a contract with the customer when they add something to their basket that they are buying that item at that price.

So to show your basket you would still do the join, but the product name, description etc would come from the product table (P.Name, P.Description in the above query) but you would get the price from the basket table (B.Price).


这篇关于电子商务ASP网 - 在2个表之间查询SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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