I was trying to add two quantities at different rows of same description i.e same product_name and same item_pack.1st I want to check the table if it contains the same description or not by comparing with the first record and so on. When found, I'll add up the quantities and then to delete that particular row (to avoid duplicate search). But when I delete the row the particular row, next time it throws an out of index exception.
Below Is the given code. Any suggestions appreciated.
Expand|Select|Wrap|Line Numbers
- Try
- If con.State = ConnectionState.Closed Then
- con.Open()
- End If
- 'Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select p.product_name, p.item_pack,p.product_manufacturer,p.product_description,w.available_qty, w.product_mrp from product_master as p inner join warehouse_master as w on p.product_name=w.product_name and p.item_pack= w.item_pack ", con)
- Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select product_name , item_pack, available_qty from warehouse_master order by serial_no", con)
- Dim ds As DataSet = New DataSet
- Dim ds1 As DataSet = New DataSet
- da.Fill(ds, "Warehouse1")
- DGV1_Home.DataSource = ds.Tables(0)
- DGV1_Home.Show()
- Dim row, row1, rowcnt As Integer
- 'Dim nm, nm1, pack, pack1 As String
- rowcnt = ds.Tables(0).Rows().Count - 1
- For row = 0 To rowcnt
- MessageBox.Show("inside 1st for loop" & rowcnt)
- Dim qty As Integer
- qty = ds.Tables(0).Rows(row).Item(2)
- For row1 = 1 To rowcnt
- MessageBox.Show("inside 2nd for loop" & rowcnt)
- If ds.Tables(0).Rows(row).Item(0) = ds.Tables(0).Rows(row1).Item(0) And ds.Tables(0).Rows(row).Item(1) = ds.Tables(0).Rows(row1).Item(1) Then
- MessageBox.Show("iif " & rowcnt)
- qty += ds.Tables(0).Rows(row1).Item(2)
- ds.Tables(0).Rows.RemoveAt(row1)
- rowcnt = ds.Tables(0).Rows.Count - 1
- End If
- MessageBox.Show(rowcnt)
- Next
- MessageBox.Show(ds.Tables(0).Rows(row).Item(0) & qty)
- rowcnt = ds.Tables(0).Rows.Count - 1
- MessageBox.Show("out side 2nd loop" & rowcnt)
- Next
- MessageBox.Show("out side 1st for loop")
- 'DGV1_Home.DataSource = ds.Tables(0)
- 'DGV1_Home.Show()
- Catch ex As Exception
- MessageBox.Show(ex.ToString)
- Finally
- con.Close()
- End Try
Sl.No anacin stripe10 10
2 dependal stripe10 25
3 anacin stripe20 18
4 anacin stripe10 24
5 eno satchet 80
6 eno bottle 10
7 axacef stripe20 25