-2
Private Sub btnupload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupload.Click
    Dim Data As String = ""
    '  Dim i As Integer = 0
    '  For Each i As DataGridViewRow In DataGridView1.Rows
    For i As Integer = 0 To DataGridView1.RowCount - 1
        'For Each i As Integer =0 to DataGridView1.
        Data = DataGridView1.Rows(i).Cells(0).Value.ToString + "~" + DataGridView1.Rows(i).Cells(1).Value.ToString + "~" + DataGridView1.Rows(i).Cells(2).Value.ToString + "~" + DataGridView1.Rows(i).Cells(3).Value.ToString + "*"

    Next

End Sub
Tim Williams
  • 137,250
  • 8
  • 88
  • 114
  • Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Guru Stron May 11 '22 at 05:47
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 11 '22 at 06:50
  • What happens if you loop to `DataGridView1.RowCount - 2`? – Jimi May 11 '22 at 15:21
  • Are you able to confirm that your datagridview does actually have 4 columns? Also you will find this type of thing is much simpler to do when iterating the data source for your grid rather than iterating the grid rows. – Hursey May 11 '22 at 20:26

0 Answers0