Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2005-03-29
Medium Priority
Last Modified: 2012-05-05

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
Question by:dn_learner
  • 4
LVL 11

Accepted Solution

sachiek earned 2000 total points
ID: 13658358
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?

LVL 11

Expert Comment

ID: 13658396
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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 11

Expert Comment

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

LVL 26

Expert Comment

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

Reading a Delimited File Using ASP.Net and VB.Net - Usage

Author Comment

ID: 13666928
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.


Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question