Solved

reading a text file which contains double Quotes is truncading the record

Posted on 2016-11-18
4
52 Views
Last Modified: 2016-11-22
In my c# application I have a common file read process which read data from database tables, Excel & text files into a dataset called ds. However the text file I am currently trying to read has imbedded quotations and commas,

Segment from text file in question

!! Name:        FG Cover Sheet Printer Channel
!! Date:        June 21, 2003
!! Version:     1.0
CHANNEL "default"
       LIKE "stdout"  

I need to read each record as a single piece of text but when for example it encounters CHANNEL "default" only CHANNEL is read into the dataset and everything after that is truncated. How can I read the text as it is displayed above line by line into a dataset ?

Connection string being used

 
connString=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\TiosFolder\TiosDownloadFiles;  Extended Properties='text;HDR=Yes;FMT=Delimited;ReadOnly=False';


reading record
conn = genRead.GetConnection("ole", connString);
Adapter = genRead.GetDataAdapter("ole", connString, sqlStmt);

OleDbConnection conn = new OleDbConnection(connString);
conn.Close();
OleDbCommand cmd = new OleDbCommand(sqlStmt, conn);
conn.Open();

Adapter.Fill(ds);
0
Comment
Question by:pclarke7
[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
  • 2
  • 2
4 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 41893680
If the double quote is not needed (meaning the field is always one word) then you can create a temporary file  in the same folder location with the quotes removed and read the new file instead.
0
 

Author Comment

by:pclarke7
ID: 41894416
Hi Miguel,
These are 3rd party files that I am processing and therefore I have no input into how they are formatted. There are double quotes embedded everywhere. I was hoping that there would be something that I could add to the connection string that would allow me to read the full record, regardless of whether it contains quotes or not.

regards
Pat
0
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 500 total points
ID: 41894625
Even if there are 3rd party files, they must comply with a format,  (else you will no be able to use or read any useful info from them)
First of all, please determine whether that is the case, because from the question description and your previous comment, it seems that the delimiters are different in the following lines:
CHANNEL "default"
       LIKE "stdout"  

Open in new window

One possible solution that I use in the past is to use the TextFieldParser class and load the dataset manually. I know more it is more work but sometimes it is not possible to use OLE classes because the file format is not compliant.
0
 

Author Closing Comment

by:pclarke7
ID: 41898008
Thanks Miguel,
took your advise and looked for another method of reading the file. Ended up using System.IO.Streamreader to read the textfile which worked well and read each line as a single record.

regards
Pat
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I hide MVVM menu items in WPF/XAML? 1 36
Change to file doesn't show up 16 77
C# Formatting DateTime String Value 5 51
global Variable - 2 functions in powershell 1 21
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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