error when i have a different delimeter when reading a .csv file


I have  code that reads a .csv file and displays the data in a datagrid. It works fine when the delimeter is a COMMA, but gives me an error when i have a PIPE delimeter.  Please help me out.

Here is the code that iam using to accomplish the task
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ''Put user code to initialize the page here
        Dim PathtoTextFile As String = "c:\DataFolder\"
        Dim oCon As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                     "Data Source=" & PathtoTextFile & ";" & _
                     "Extended Properties=""text;HDR=YES;FMT=Delimited""")

        Dim oCmd As New System.Data.OleDb.OleDbDataAdapter("SELECT program, description FROM datafile.csv", oCon)
        Dim dstemp As New DataSet

        DataGrid1.DataSource = dstemp
    End Sub

Here is the error that i get:
Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters.

Source Error:

Line 48:
Line 49:         Dim dstemp As New DataSet
Line 50:         oCmd.Fill(dstemp)
Line 51:
Line 52:         DataGrid1.DataSource = dstemp
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.

Why no have a small method which reads that textfile convert all the pipe symbol to comma delimiter and then try to display in datagrid?


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
There is one intresting other method also.
You can convert this csv into XML. This you can do it now with MS-Office 2003 or you need to download a utlity recently release by microsoft then can disply in datagrid.

Else you can also do it by yourself. Look into this article.
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

If you still not able to solve it let me know.

have a look at this link .. explains reading a tab delimted text file ...

Reading a Delimited File Using ASP.Net and VB.Net - Usage
dn_learnerAuthor Commented:
Hi guys,

i really appreicate the help you provided.

as suggested by sachiek,  i read the csv file, replaced all the PIPES with a COMMA and wrote the data to a new file. And then I used that new file in my SELECT statement to read the data and displayed it into a datagrid.

I added the following code before the block of code that you see above in my original post.
objStreamReader = File.OpenText(MapPath("datafile.csv"))
        strInput = objStreamReader.ReadLine()
        While strInput <> Nothing
             strInput = Replace(strInput, "|", ",")
            strInput = objStreamReader.ReadLine()
        End While
Please let me know if you like the code or would u have done it differently.

Thanks a lot.

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

From novice to tech pro — start learning today.

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.