Mokmeuh
Mokmeuh

Reputation: 885

Oledeb command builder, got it wrong

Using con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = Mokmeuh.accdb")
        con.Open()
        dAdapter.UpdateCommand = New OleDbCommand("UPDATE Articles SET Nom = @p1, Prix = @p2, Quantité = @p3 WHERE ((Nom = @p1) AND ((@p2 = 1 AND Prix IS NULL) OR (Prix = @p2)) AND ((@p2 = 1 AND Quantité IS NULL) OR (Quantité = @p3)))", con)
        dAdapter.UpdateCommand.Parameters.Add("@p1", OleDbType.VarChar, 4, "Nom")
        dAdapter.UpdateCommand.Parameters.Add("@p2", OleDbType.Single, 4, "Prix")
        dAdapter.UpdateCommand.Parameters.Add("@p3", OleDbType.Integer, 4, "Quantité")

        dAdapter.Update(dSet.Tables("Articles_table"))
    End Using

This would be my command with my parameters but I throw me an error so I get it wrong but I don't know how to fix it, the error is telling you : The Update affected 0 where it should have affected one

So, where do i get this wrong

Edit : database type

enter image description here

Upvotes: 0

Views: 96

Answers (1)

Steve
Steve

Reputation: 5545

Unfortunately, we dont know your data well enough to help you. But, here is how you can help yourself. Turn that UPDATE into a SELECT and see what results you get. Your WHERE sql seems strange but again, without your data, it may just look strange when it is perfectly logical.

SELECT * FROM Articles WHERE ((Nom = @p1) AND ((@p2 = 1 AND Prix IS NULL) OR (Prix = @p2)) AND ((@p2 = 1 AND Quantité IS NULL) OR (Quantité = @p3)))

Upvotes: 1

Related Questions