OpenConn()

        For Each li As Windows.Forms.ListViewItem In ListView1.Items


            With OleDa

                .UpdateCommand = New OleDb.OleDbCommand()
                .UpdateCommand.CommandText = "UPDATE [Inventry] SET [CODE] = @CODE , [ITEM] = @ITEM , [QTY] = val(QTY) - @QTY , [SPRICE] = @SPRICE , [PPRICE] = @PPRICE WHERE (CODE = ?)"
                .UpdateCommand.Connection = Con
                .UpdateCommand.Parameters.Add("@CODE", OleDb.OleDbType.VarWChar, 50, "CODE").Value = li.SubItems(1)
                .UpdateCommand.Parameters.Add("@ITEM", OleDb.OleDbType.VarWChar, 50, "ITEM").Value = li.SubItems(2).Text
                .UpdateCommand.Parameters.Add("@QTY", OleDb.OleDbType.VarWChar, 50, "QTY").Value = li.SubItems(3).Text
                .UpdateCommand.Parameters.Add("@SPRICE", OleDb.OleDbType.VarWChar, 50, "SPRICE").Value = "@SPRICE"
                .UpdateCommand.Parameters.Add("@PPRICE", OleDb.OleDbType.VarWChar, 50, "PPRICE").Value = "@PPRICE"

                .UpdateCommand.ExecuteNonQuery()

            End With
        Next
        CloseConn()

Edited 3 Years Ago by mike_2000_17: Fixed formatting

i want , when i click save button then all items in listview will subtract qty from ms access where is code..........

You will need a for statment to cycle through the listview.

(This only works where a unique value is present for each entry.) (Like an ID Column)

'This assumes that the CODE field is unique to each database entry!!
For Each li as ListViewItem In ListView1.Items
    With OleDa
        .DeleteCommand = "DELETE FROM table WHERE CODE=@CODE"
        .DeleteCommand.Parameters.Add("@CODE",OleDb.OleDbType.VarWChar, 50, "CODE").Value = li.SubItems(1))
        .DeleteCommand.ExecuteNonQuery()
    End With
Next

Edited 4 Years Ago by Begginnerdev

This article has been dead for over six months. Start a new discussion instead.