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()

Recommended Answers

All 3 Replies

What is it about?

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.