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?
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
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 ConnectWise

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.