Hi again, I'm having a trouble in updating an item from listview to database
I try this code , but it says syntax error in Update
nod=name of dish , qty = quantity
TBLORDERS - nod[text], qty[text], price[text]
lvorder - qty , [subitems] - name of dish, price
Dim sql = "SELECT * FROM TBLORDERS WHERE nod='" & lvorder.Items(0).SubItems(1).Text & "'"
Dim cmd = New OleDbCommand(sql, con)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Try
If dr.Read = True Then
For Each x As ListViewItem In lvorder.Items
Dim nod As String = x.SubItems(1).Text
Dim qty As Integer = Convert.ToDecimal(x.SubItems(0).Text)
Dim price As Integer = Convert.ToDecimal(x.SubItems(3).Text)
sql = "Update TBLORDERS set" & _
"qty = qty + ? " & _
"price = price + ? " & _
"where nod = ?"
cmd = New OleDbCommand(sql.ToString, con)
cmd.Parameters.AddWithValue("@qty", qty)
cmd.Parameters.AddWithValue("@price", price)
cmd.Parameters.AddWithValue("@nod", nod)
cmd.ExecuteNonQuery()
cmd.dispose
MsgBox("update")
Next
Else
For Each x As ListViewItem In lvorder.Items
sql = "insert into TBLORDERS (tbl,nod,qty,price) values ('" _
& lbltable.Text & "','" _
& x.SubItems(1).Text & "','" _
& x.SubItems(0).Text & "','" _
& x.SubItems(3).Text & "')"
Dim ccmd = New OleDb.OleDbCommand(sql, con)
ccmd.ExecuteNonQuery()
ccmd.Dispose()
Next
MsgBox("save")
Me.Refresh()
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try