【问题标题】:Clicking the add button adds the value to all same value in product_stock单击添加按钮将值添加到 product_stock 中的所有相同值
【发布时间】:2018-11-06 21:26:39
【问题描述】:

当我单击添加按钮时,它会将 Textbox4 的值添加到数据库中 product_stock 中的所有相同值。

conn.Open()
    Using com As New SqlCommand("UPDATE table_addsub SET [product_stock]=[product_stock] + @qty2 WHERE [product_stock]=@qty1", conn)
        com.Parameters.AddWithValue("@qty1", Me.TextBox3.Text)
        com.Parameters.AddWithValue("@qty2", Me.TextBox4.Text)
        com.ExecuteNonQuery()
        MessageBox.Show("Updated Successfully")
        LoadList()
    End Using

钉子和灯泡的产品库存是 100,但是当我想在灯泡库存中添加 20 时,它也会在钉子库存中添加 20

【问题讨论】:

  • LoadList() 下的代码?并验证您的 UPDATE 声明 WHERE 子句。 Where 子句的逻辑错误。
  • 就是这样,它是按钮添加的代码。当我单击添加按钮时,它将 Textbox4 中的数量添加到 sql server 中 product_stock 中的所有相同值,这是错误的。我希望发生这种情况,当我单击添加按钮时,它会将 textbox4 中的数量添加到 textbox3 中的数量,这就是 sql server 中的 product_stock。
  • 但是你缺少 Product_id...。
  • 我修好了,谢谢先生。 :)
  • 我的错误是我调用的是 product_stock 而不是 product_id。感谢您的帮助:)

标签: asp.net sql-server vb.net


【解决方案1】:

您在 WHERE 子句中缺少产品 ID。

conn.Open()
Using com As New SqlCommand("UPDATE table_addsub SET [product_stock]=[product_stock] + @qty2 WHERE [product_Id]=@Prod_Id", conn)
    com.Parameters.AddWithValue("@Prod_Id", Me.TextBox3.Text) // Product id        
    com.Parameters.AddWithValue("@qty2", Me.TextBox4.Text) //Qty to be add.
    com.ExecuteNonQuery()
    MessageBox.Show("Updated Successfully")
    LoadList()
End Using

【讨论】:

    猜你喜欢
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多