Import a CSV file and loop through it, doing work

Private Sub btnImportCustomers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImportCustomers.Click
    Try
        Dim strFilename As String
        'Navigate to the text file.
        OpenFileDialog1.Filter = "CSV Files|*.csv|All files (*.*)|*.*"
        OpenFileDialog1.Title = "Select a CSV File"
        OpenFileDialog1.FileName = ""
        If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            strFilename = OpenFileDialog1.FileName
            Dim SR As New StreamReader(strFilename)
            Do
                Dim S As String = SR.ReadLine
                If SR.EndOfStream Then
                    Exit Do
                End If
                Dim aLine As String() = S.Split(",")
                'Import the class into Dynamics.
                dowork(aLine)
            Loop
              
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences