jezz jezz - 23 days ago 12
Vb.net Question

For Each Gridview not working properly

Can you help me on my for each loop it only saves the first row many times of the Gridview on my database. Can you please help me if what's wrong on my code. Thanks in advance.

here is my code

Using _adTransPlatts As New TradingTransactionRepository

For Each row As GridViewRow In
GridView1.Rows_adTransPlatts.AddPlatts(GridView1.Rows(0).Cells(1).Text, GridView1.Rows(0).Cells(2).Text, GridView1.Rows(0).Cells(3).Text)
Next
MsgBox("Completed")
End Using

Answer

Change GridView1.Rows(0) by currentRow

 For Each currentRow As GridViewRow In GridView1.Rows
        _adTransPlatts.AddPlatts(currentRow.Cells(1).Text, currentRow.Cells(2).Text, currentRow.Cells(3).Text)
 Next

GridView1.Rows(0) refers always to the first row