title: how to loop throw all rows in data grid view in vb.net windows application
body: <p>i have a data grid view..in update button i wrote the code like this</p>
  
  <pre><code>Dim cid As Integer
          Dim dtid As Integer
          Dim cmpname As String
          Dim dtname As String
          Dim dtPhone As String
          Dim dtEmail As String
  Dim rv = DirectCast(bSource.Current, DataRowView)
          cid = rv.Row.Field(Of Integer)("Cid")
          dtid = rv.Row.Field(Of Integer)("dtId")
          cmpname = rv.Row.Field(Of String)("CompanyName")
          dtname = rv.Row.Field(Of String)("dtName")
          dtPhone = rv.Row.Field(Of String)("dtPhone")
          dtEmail = rv.Row.Field(Of String)("dtEmail")
   adapter.UpdateCommand = New SqlCommand("UPDATE CompanyMaster_tbl SET CompanyName = @CompanyName", con)
          adapter.UpdateCommand = New SqlCommand("update DepartmentMaster_tbl set dtName = @dtName,dtPhone = @dtPhone,dtEmail = @dtEmail  where dtId=@dtid", con)
          adapter.UpdateCommand.Parameters.AddWithValue("@Cid", cid)
          adapter.UpdateCommand.Parameters.AddWithValue("@CompanyName", cmpname)
          adapter.UpdateCommand.Parameters.AddWithValue("@dtId", dtid)
          adapter.UpdateCommand.Parameters.AddWithValue("@dtName", dtname)
          adapter.UpdateCommand.Parameters.AddWithValue("@dtPhone", dtPhone)
          adapter.UpdateCommand.Parameters.AddWithValue("@dtEmail", dtEmail)
          adapter.UpdateCommand.ExecuteNonQuery()
  </code></pre>
  
  <p>i am new in datagridview.same time if i update multiple row,it s affecting last updated rows,,so i need to loop throw all rows in datagridview..how i can achieve that..</p>
  
  <p>so i given the entire code inside the loop like this</p>
  
  <pre><code>For Each row As DataGridViewRow In gv.Rows
      'my code here
  Next
  </code></pre>
  
  <p>but then also updating last updated row?? Thanks in advance</p>