Solved

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

Posted on 2016-11-18
4
55 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

728 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