troubleshooting Question

C# -- remove comma when reading TXT file ?

Avatar of finance_teacher
finance_teacher asked on
.NET ProgrammingC#
17 Comments1 Solution1106 ViewsLast Modified:
The below code reads in my below "John Doe" variance.txt correctly.

NAME,FILE#,SSN,CHECKVIEWPAYDATE,Total_Hrs,CHECKVIEWGROSSPAYA,HOMEDEPARTMENT
"John Doe",229999,9263,12/06/2010,56,278.72,104002
"Jane Doe",181,6331,12/06/2010,40,74,101301
"John Smith",1041,1207,12/06/2010,40,12,101001
----------------------------------------------------------------
How can I change the code to remove the , or replacing it with
a space or something so it reads in the below "John, Doe"
as one column ?

NAME,FILE#,SSN,CHECKVIEWPAYDATE,Total_Hrs,CHECKVIEWGROSSPAYA,HOMEDEPARTMENT
"John, Doe",229999,9263,12/06/2010,56,278.72,104002
"Jane, Doe",181,6331,12/06/2010,40,74,101301
"John, Smith",1041,1207,12/06/2010,40,12,101001

----------------------------------------------------------------
        private DataSet ReadFile(string filePath)
        {
            OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Path.GetDirectoryName(filePath) + "; Extended Properties = \"Text;HDR=YES;FMT=Delimited\"");
            conn.Open();
            OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM " + System.IO.Path.GetFileName(filePath), conn);
            DataSet ds = new DataSet("Temp");
            adapter.Fill(ds);

            return ds;
        }
----------------------------------------------------------------
        public bool ImportFileVariance()
        {
            string filePath = @"C:\import\variance.txt";

            DataSet ds = ReadFile(filePath);

            return dbAccess.ImportVarianceRecords(ds.Tables[0]);
        }
----------------------------------------------------------------
ASKER CERTIFIED SOLUTION
Todd Gerbert
Senior Engineer
Join our community to see this answer!
Unlock 1 Answer and 17 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros