-1

我有一个客户购物车,它显示客户想要购买的购物车。我想在客户购物车上删除一行。

购物车显示基于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

这是客户购物车展示

这是数据库表customercart

这是 sql 自定义

这是我的 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>

我的网格视图

<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
4

2 回答 2

1

可能是未设置 cust_id 值,请尝试将 DataKeyNames 属性添加到您的 gridview,即

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" DataKeyNames="cust_id" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
于 2018-10-28T11:05:06.887 回答
0

如果我正确理解您,您的字段和架构。然后似乎您想删除购物车项目。您可能可以使用这样的查询

"Delete from FROM tableCustomerCart where cart_id = @cart_id"

免责声明,我不能对你伤害命令的人负责,否则这个代码会伤害你

于 2018-10-28T07:20:25.077 回答