title: How to save newly added data in a row or rows from DataGridView  into SQL Server when the user clicks a button
body: <p>I'd be grateful if could modify the following code for me so that it save data row by row from a DataGridView into SQl Server. Currently, the code saves data from all rows at time instead of saving only the recently added data in a row or rows when the user clicks a button.</p>
  
  <pre><code>Dim cmd As New SqlCommand
          Try
              Dim i As Integer
              For i = 0 To dgMarksEntry.Rows.Count - 1
                  If dgMarksEntry.Item(1, i).Value = "" Then
                  Else
                      qry = "insert into StudentDetails.MarksEntry values ('" &amp; dgMarksEntry.Item(0, i).Value &amp; "', '" &amp; dgMarksEntry.Item(2, i).Value &amp; "','" &amp; dgMarksEntry.Item(3, i).Value &amp; "','" &amp; dgMarksEntry.Item(4, i).Value &amp; "') "
                      cmd = New SqlCommand(qry, cn)
                      cmd.ExecuteNonQuery()
                  End If
              Next
          Catch ex As Exception
              MessageBox.Show("Insert Error: " &amp; ex.Message)
          Finally
          End Try
          MessageBox.Show("Record successfully saved", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
  </code></pre>