Razvan Balaci Razvan Balaci - 6 months ago 15
Vb.net Question

How to update database when itemselected on listbox

I need a help.

I need to know how i can update my database when listbox item is selected, and what i want to update is the quantity.

That is the design that i have:

enter image description here

What i want is:
When i select field "Narnia" i want to decrease the quantity on my database.

I already tried that by myself but when i select an item, that decrease all of quantitys, not only on "Narnia"

cmd = New OleDb.OleDbCommand("UPDATE Livrosescola SET Quantidade = Quantidade - 1 ", myConnection)

Answer

You must have a criterion to specify in your query that you wan modify just the row of ""Narnia" or an element selected :

So your query must be something like :

 cmd = New OleDb.OleDbCommand("UPDATE Livrosescola SET Quantidade = Quantidade - 1 
 where NomeLivro like '*" & ListBox1.SelectedItem & "*'", myConnection)