pclarke7
asked on
reading a text file which contains double Quotes is truncading the record
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=Micros oft.ACE.OL EDB.12.0;D ata Source=C:\TiosFolder\TiosD ownloadFil es; Extended Properties='text;HDR=Yes;F MT=Delimit ed;ReadOnl y=False';
reading record
conn = genRead.GetConnection("ole ", connString);
Adapter = genRead.GetDataAdapter("ol e", connString, sqlStmt);
OleDbConnection conn = new OleDbConnection(connString );
conn.Close();
OleDbCommand cmd = new OleDbCommand(sqlStmt, conn);
conn.Open();
Adapter.Fill(ds);
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=Micros
reading record
conn = genRead.GetConnection("ole
Adapter = genRead.GetDataAdapter("ol
OleDbConnection conn = new OleDbConnection(connString
conn.Close();
OleDbCommand cmd = new OleDbCommand(sqlStmt, conn);
conn.Open();
Adapter.Fill(ds);
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.
ASKER
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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