?
Solved

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

Posted on 2005-03-29
6
Medium Priority
?
316 Views
Last Modified: 2012-05-05
Hi,

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
        oCmd.Fill(dstemp)

        DataGrid1.DataSource = dstemp
        DataGrid1.DataBind()
    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
 
------------------------------------------------------------------------------------------------------------------
0
Comment
Question by:dn_learner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 11

Accepted Solution

by:
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?


Sachi
0
 
LVL 11

Expert Comment

by:sachiek
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.
http://www.devcity.net/Articles/36/1/delimit_xml.aspx
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

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


Sachi
0
 
LVL 26

Expert Comment

by:Rejojohny
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
http://www.dotnet247.com/247reference/a.aspx?u=http://www.devarticles.com/c/a/ASP.NET/Reading-a-Delimited-File-Using-ASP.Net-and-VB.Net/
0
 

Author Comment

by:dn_learner
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, "|", ",")
            objStreamWriter.Write(strInput)
            objStreamWriter.Write(objStreamWriter.NewLine())
            strInput = objStreamReader.ReadLine()
        End While
        objStreamReader.Close()
        objStreamWriter.Close()
---------------------------------------------------------------------------------------------------------
Please let me know if you like the code or would u have done it differently.

Thanks a lot.


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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