i have never imported anything from a .csv file before

i have an app that downloads a .csv file from a website and saves it locally (could probably even skip this step and just read it from the website)

it then needs to read the .csv file and insert the data from the .csv file into a mysql database.

i know how to insert into mysql, i just dont know how to read from the .csv file

does anyone have any examples of this? i searched google for awhile but couldnt really find anything that i grasped or worked for me.

using .net 3.5 vb2k8

6 Years
Discussion Span
Last Post by jlego

See if this helps for populating a ListView from a .csv file.

'// file located here: http://seepeoplesoftware.com/downloads/older-versions/11-sample-csv-file-of-us-presidents.html
        Dim myCSVfile As String = "C:\USPresident Wikipedia URLs Thmbs HS.csv"
        '// read File into Arrays.
        Dim arFileLines() As String = IO.File.ReadAllLines(myCSVfile)
        '// read line 1 to get Columns.
        Dim arLineContent() As String = arFileLines(0).Split(",")
        '// add Columns to ListView.
        ListView1.View = View.Details
        For Each lineArray As String In arLineContent
        '//------ populate ListView.
        '// start with line 2 since line 1 is for Columns.
        For i As Integer = 1 To arFileLines.Length - 2 '// -2 to remove the last president. :D
            arLineContent = arFileLines(i).Split(",") '// split line into arrays.
            '// create new item and subitems.
            Dim newLvItem As New ListViewItem
            With newLvItem
                .Text = arLineContent(0) '// add Item.
                For x As Integer = 1 To arLineContent.Length - 1
                    .SubItems.Add(arLineContent(x)) '// add SubItems.
            End With
            ListView1.Items.Add(newLvItem) '// add to ListView.

thanks code order - i just changed a few things and that worked without issue.

appreciate it

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.