Read from a csv file

I have a excel file which i converted to a csv and freom this csv, i have to read the data in a vb.net application.
This excel file has 5 columns in each row.
In my code, i used the "," delimiter to retrieve the data.
But, the problem is each column is coming out seperated by a delimiter.
Why is this happening?
Is this something to do with the csv file i generated?


Public Sub getvals()
        Dim filetoread As String
        filetoread = "C:\Users\MyPC\Desktop\Data with addresses.csv"
        Dim filestream As StreamReader
        filestream = File.OpenText(filetoread)
        Dim readcontents As String
        readcontents = filestream.ReadToEnd()
        Dim textdelimiter As String
        textdelimiter = ","
        Dim splitout = Split(readcontents, textdelimiter)
        txt_Addr.Text = readcontents & "<br>"
        Dim dt As New DataTable
        Dim val As New DataColumn
        dt.Columns.Add(val)

        Dim dr As DataRow

        Dim i As Integer
        For i = 0 To UBound(splitout)
            dr = dt.NewRow
            dr.Item(0) = splitout(i).ToString
            dt.Rows.Add(dr)
       
        Next
        DataGridView1.DataSource = dt

        filestream.Close()
    End Sub
rowternetAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rowternetAuthor Commented:
The excel file that i was given has 5 columns(addr1, addr2, city, state, zip).
Now, when i save it as csv, each column is seperated by a ",". Where as i want the whole row to be seperated by a ",".
How can i do this?

0
stsanzCommented:
Please post a sample CSV file with a few sample data
0
stsanzCommented:
In your DataRow, your loop fills only Item(0).
What value do you want to fill Item(0) ? addr1, addr2, city, state or zip ?

>> Now, when i save it as csv, each column is seperated by a ","

This is the correct format for a CSV file. Each column is separated by a "," and each row is separated by a newline.

You should read the CSV file line by line, then split each line into columns.
0
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

rowternetAuthor Commented:
split(Environment.newline) shuld be used i guess. I am able to seperate each row now.
Thanks
0
stsanzCommented:
>> split(Environment.newline) shuld be used i guess

This way you will fill Item(0) with a whole row of data "addr1, addr2, city, state, zip".
Is that what you want ?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rowternetAuthor Commented:
StSanz, That is what i wanted.
May be i framed my question wrong.
Now, i have to retrieve latitude and longitude and insert them in to the csv file adn then export it to excel.
I am working on it.

0
rowternetAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.