title: How to get all data from datagridview into ms access using vb 10?
body: <p>I am using vb 10 and ms access for database. I have a <code>DataGridView</code> which contains two column <code>("Address", "City")</code>. Every time I save two rows from each column to my database table. I always retrieve a total of 6 rows with 2 column each. The 1st and 2nd row of db are the same as the 1st row of dgview, the 3rd and 4th row of db are the same as the 2nd row of <code>dgview</code> while the 5th and 6th row of dbase are blank.</p>
  
  <p>I don't know how to make my For statement right. I have researched so many links but I didn't find any close answer. Sorry for the inconvenience, hope you help me guys. THANKS!</p>
  
  <p>my codes(under <code>cmdSave_Click</code>):</p>
  
  <pre><code>Sub DataGridViewDetails()
      Dim Address, City As String
  
      For i As Integer = 0 To Me.DataGridView.RowCount - 1
  
          Address = Me.DataGridView.Item(0, i).Value
          City = Me.DataGridView.Item(1, i).Value
  
          sql = "insert into Address(Address1 ,City) values('" &amp; Address &amp; "','" &amp; City &amp; "')"
  
          Dim comm As New OleDb.OleDbCommand
          comm.CommandText = sql
          comm.Connection = con2
          con2.Open()
          comm.ExecuteNonQuery()
  
          da.SelectCommand = comm
          dr = comm.ExecuteReader
          comm.Dispose()
          MsgBox("Address Details Added!", MsgBoxStyle.Information, "Add")
          con2.Close()
  
      Next
  End Sub
  </code></pre>