Kamis, 21 Mei 2015

Koding Simpan - Update

Try
            For i As Integer = 0 To ListView1.Items.Count - 1
                SQL2 = "INSERT INTO DTJUAL VALUES('" & TXTNOFAKTUR.Text & "','" & ListView1.Items(i).SubItems(0).Text & "','" & ListView1.Items(i).SubItems(2).Text & "','" & ListView1.Items(i).SubItems(4).Text & "')"
                connection.Open()
                adapter.InsertCommand = connection.CreateCommand
                adapter.InsertCommand.CommandText = SQL2
                adapter.InsertCommand.ExecuteNonQuery()
                connection.Close()

                'TAMBAHKAN UPDATE STOK
                SQL4 = "SELECT * FROM TBLBRG WHERE KODEBRG ='" & ListView1.Items(i).SubItems(0).Text & "'"
                connection.Open()
                With command2
                    .CommandText = SQL4
                    .Connection = connection
                    reader = .ExecuteReader
                End With

                Try
                    reader.Read()
                    If reader.HasRows = True Then
                        STOK = reader.GetValue(3)
                    End If
                Finally
                    reader.Close()
                End Try
                connection.Close()


                SQL3 = "UPDATE TBLBRG SET STOK = '" & STOK + ListView1.Items(i).SubItems(2).Text & "' WHERE KodeBRG = '" & ListView1.Items(i).SubItems(0).Text & "'"
                connection.Open()
                adapter.UpdateCommand = connection.CreateCommand
                adapter.UpdateCommand.CommandText = SQL3
                adapter.UpdateCommand.ExecuteNonQuery()
                connection.Close()


            Next