我有一个客户购物车,其中显示了客户想要购买的购物车。我要在客户购物车上删除行。
基于cust_id
的购物车显示。
我正在使用此查询来显示。
SELECT
tableCustomerCart.cart_quantity, tableFoodDetail.food_title,
tableFoodDetail.food_price, tableFoodDetail.food_image,
tableCustomerCart.cart_price
FROM
tableFoodDetail
INNER JOIN
tableCustomerCart ON tableFoodDetail.food_id = tableCustomerCart.cart_id
WHERE
tableCustomerCart.cust_id = @cust_id
我的问题是删除特定ID(cust_id
)的特定行的查询是什么?
这是我的sql数据源。
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM tableCustomerCart WHERE cust_id=@cust_id" SelectCommand="SELECT tableCustomerCart.cart_quantity, tableFoodDetail.food_title, tableFoodDetail.food_price, tableFoodDetail.food_image, tableCustomerCart.cart_price FROM tableFoodDetail INNER JOIN tableCustomerCart ON tableFoodDetail.food_id = tableCustomerCart.cart_id WHERE tableCustomerCart.cust_id = @cust_id">
<DeleteParameters>
<asp:Parameter Name="cust_id"/>
</DeleteParameters>
<SelectParameters>
<asp:SessionParameter Name="cust_id" SessionField="cust_id" />
</SelectParameters>
</asp:SqlDataSource>
我的Gridview
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowDeleteButton="True" />
<asp:BoundField DataField="cart_quantity" HeaderText="cart_quantity" SortExpression="cart_quantity" />
<asp:BoundField DataField="food_title" HeaderText="food_title" SortExpression="food_title" />
<asp:BoundField DataField="food_price" HeaderText="food_price" SortExpression="food_price" />
<asp:BoundField DataField="food_image" HeaderText="food_image" SortExpression="food_image" />
<asp:BoundField DataField="cart_price" HeaderText="cart_price" SortExpression="cart_price" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
“删除”标签。
DELETE FROM tableCustomerCart WHERE cust_id=@cust_id
答案 0 :(得分:1)
可能未设置cust_id值,请尝试将DataKeyNames属性添加到您的网格视图中,即
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" DataKeyNames="cust_id" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
答案 1 :(得分:0)
如果我正确地理解您,您的字段和架构。然后,您似乎要删除购物车项目。您可能会使用这样的查询
"Delete from FROM tableCustomerCart where cart_id = @cart_id"
免责声明 ,对于您要订购的人,我不承担任何责任,否则会因该代码而受伤