Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2016-11-18
4
Medium Priority
?
59 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 1500 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

730 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