Really need help please
this is my code:

 Sub updteWS()
        Dim sql = "select Count(*) from ItemProduct where Code= ?"
        Dim cmd = New OleDbCommand(sql, conn)
        cmd.Parameters.AddWithValue("@Code", LVCart.Items(0).SubItems(0).Text)

        Dim result As Integer = Convert.ToInt32(cmd.ExecuteScalar())
        cmd.Parameters.Clear()
        cmd.Dispose()

        If result > 0 Then
            For Each x As ListViewItem In LVCart.Items
                Dim Stocks_WS1 As Integer = 1

                sql = "UPDATE ItemProduct SET " & _
                                         "Stocks_WS = Stocks_WS - ?" & _
                                         "WHERE cnt >= numexpected AND CODE = ?"
                cmd = New OleDbCommand(sql.ToString, conn)

                cmd.Parameters.AddWithValue("@Stocks_WS", Stocks_WS1)
                cmd.Parameters.AddWithValue("@CODE", x.SubItems(0).Text)
                cmd.ExecuteNonQuery()

                sql = "UPDATE ItemProduct SET cnt='0'" +
       "WHERE cnt >= numexpected AND CODE=?"
                cmd = New OleDbCommand(sql.ToString, conn)
                cmd.Parameters.AddWithValue("@CODE", x.SubItems(0).Text)
                cmd.ExecuteNonQuery()
            Next
        Else

        End If
        cmd.Parameters.Clear()
        cmd.Dispose()
    End Sub

database field : CODE, Stocks_WS, Stocks_retail, cnt , numexpected
Stocks_WS - stocks for wholesale
Stocks_retail - stocks for retail
cnt - the number of times where the items brought buy the customer (it will only count when the customer buys a retail)
numexpected - it is the estimated number of items per unit (example 100pcs per box)
heres the example (stocks_ws = 1 , stocks_retail = 100 , numexpected = 100)

*My problem is when i buy an 2 or more items, it keeps decreasing the stocks_ws even i bought retail.
i want to decrease the stocks_ws when the [cnt] is greater than or equal to [numexpected]

heres my code for wholesale and retail

connect()
            For w = 0 To LVCart.Items.Count - 1
                If LVProduct.Items(w).SubItems(4).Text = LVProduct.Items(w).SubItems(5).Text Then
                    GoTo Here
                End If
                If LVProduct.Items(w).SubItems(4).Text = LVProduct.Items(w).SubItems(5).Text Then
                    GoTo there
                End If
            Next

            If chkWholesale.Checked = True Then
Here:
                connect()
                sql = "UPDATE ItemProduct SET STOCKS_WS = STOCKS_WS - " & LVCart.Items(a).SubItems(4).Text & " WHERE CODE = '" & LVCart.Items(a).Text & "'"
                cmd = New OleDb.OleDbCommand(sql, conn)
                cmd.ExecuteNonQuery()
                cmd.Dispose()
            End If

            If ckretail.Checked = True Then
there:
                connect()
                sql = "UPDATE ItemProduct SET STOCKS_Retail = STOCKS_Retail  - " & LVCart.Items(a).SubItems(4).Text & " WHERE CODE = '" & LVCart.Items(a).Text & "'"
                cmd = New OleDb.OleDbCommand(sql, conn)
                cmd.ExecuteNonQuery()

                Dim CODE As String = LVCart.Items(a).Text
                Dim cnt As Integer = Convert.ToDecimal(LVCart.Items(a).SubItems(4).Text)
                sql = "UPDATE ItemProduct SET " & _
                                      "cnt = cnt + ? " & _
                                      "WHERE CODE = ?"
                cmd = New OleDbCommand(sql.ToString, conn)

                cmd.Parameters.AddWithValue("@cnt", cnt)
                cmd.Parameters.AddWithValue("@dte", CODE)

                cmd.ExecuteNonQuery()


                 updteWS()
                cmd.Dispose()

            Else
            End If

               cmd.Dispose()
            FillLView()
        Next

thank you in advance :D

please guys help me. i tried another code but the result is the same. It only works when i buy 1 item only but when i try two or more items, it keeps reducing the stocks number for wholesale even though i buy in retail.

Wow, I didn't know GoTo was still valid, please stop that.

Well first of all, the flow of this entire operation is a little shaky, however looking at this:

                If LVProduct.Items(w).SubItems(4).Text = LVProduct.Items(w).SubItems(5).Text Then
                    GoTo Here
                End If
                If LVProduct.Items(w).SubItems(4).Text = LVProduct.Items(w).SubItems(5).Text Then
                    GoTo there
                End If

Both conditions are exactly the same so if the conditions are correct it will always goto Here, and never there.

in fact GoTo there will never be called, Here seems to be where your Whole sale stuff is... Wholesale is always going to be called if the above conditions are correct.

Also not understanding what your check boxes are doing and when, there is a chance when you GoTo Here, there's code will be executed afterwards.

Edited 1 Year Ago by J.C. SolvoTerra

Also, GoTo exits the loop meaning the conditions within that particular loop will only ever be true once. I can see that this is in another loop but it's not clear from here what for.

thank you J.C. SolvoTerra, i find the error why it is not working,

If LVProduct.Items(w).SubItems(4).Text = LVProduct.Items(w).SubItems(5).Text Then
                    GoTo Here
                End If
                If LVProduct.Items(w).SubItems(4).Text = LVProduct.Items(w).SubItems(5).Text Then
                    GoTo there
                End If



        `

its just the same. thats why its not working

For what it's worth, GOTOs are evil. Before the advent of structured programming constructs like IF-THEN-ELSE, GOTOs were a necessary evil, but used properly they could be tolerated. I, myself, have (on rare occasions) used GOTOs to escape from nested constructs, but I have never had to resort to that since the introduction of TRY-CATCH. I strongly suggest that you rewrite your code to eliminate your GOTOs.

@Reverend Jim, thanks, i tried the try and catch and its more reliable than GOTO
thanks guys for helping, i got it now

This question has already been answered. Start a new discussion instead.