我想使程序如果数据已经存在就进行更新,否则它将插入

时间:2019-04-10 13:32:39

标签: visual-studio ms-access

我想使用Visual Studio和Ms Access为我的公司制作一个仓库管理系统程序。正如我在标题上所描述的,我想使If Function在数据为新数据的地方插入数据,而在数据已经存在的情况下更新。

因为我是编程新手,所以我遵循了这家伙的说明https://www.youtube.com/watch?v=q19OXha1jDw 并创建一个类,以便我可以在access.Execquery函数中进行查询。

Private Sub UpdateDb(KimapValue As String, PoValue As String, LocValue As String, QtyRecValue As String, DateVal As String, PemasokVal As String)
    Access.AddParam("@KiValue", KimapValue)
    Access.AddParam("@PoVal", PoValue)
    Access.AddParam("@LocVal", LocValue)
    Access.AddParam("@QtyValue", QtyRecValue)
    Access.AddParam("@DateValue", DateVal)
    Access.AddParam("@PasokValue", PemasokVal)

    Access.ExecQuery("SELECT * FROM dbWarehouse
                       CASE WHEN NoPo = @PoVal AND Kimap = @KiValue AND Lokasi = @LocVal THEN
                        UPDATE dbWarehouse SET Quantity = Quantity + @QtyValue WHERE NoPo = @PoVal AND Lokasi = @LocVal
                       ELSE
                        INSERT INTO dbWarehouse (Kimap, NoPo, Lokasi, Quantity, TanggalMasuk, Pemasok) VALUES (
                        @KiValue, @QtyValue, @LocVal, @PoVal, @DateValue, @PasokValue)
                        END ")

End Sub

Private Sub ReceiveBTN_Click(sender As Object, e As EventArgs) Handles ReceiveBTN.Click
    UpdateDb(KimapTB.Text, NopoTB.Text, LokasiTB.Text, QtyTB.Text, TanggalMasukDTP.Value.ToString, PemasokTB.Text)

    MsgBox("Data Receive sudah dimasukkan, silahkan letakkan barang di " + LokasiTB.Text + " !")
End Sub

如果NoPo和Kimap和Lokasi为TRUE,我希望输出将更新,否则它将插入

ps:对不起,我的英语不好

0 个答案:

没有答案