Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. problem in reading .csv files

problem in reading .csv files

Scheduled Pinned Locked Moved C#
csharpwindows-adminhelpquestion
8 Posts 6 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    montu3377
    wrote on last edited by
    #1

    Hi All, I have two C# windows application, both are reading .csv file and doing some processing, however there is one difference between both .csv file. One .csv file is using comma (,) as delimiter (separater) and other .csv file is using |(Pipe) character as delimiter (separater), so basically that is customized seperater. Both .csv file is used by my two different C# windows application. Now here is a problem. My first application used .csv file which has comma(,) as seperater and i am using provider as "Microsoft.Jet.OLEDB.4.0" to reading that file with following connectionstring: string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvfile.Directory.FullName + ";Extended Properties='text;HDR=Yes'"; As by default it's comma, so i don't have to do any changes in my registry to read this file, it's simple but problem came when i am using my other C# windows application. Second C# windows application is using other .csv file which has |(Pipe) character as seperater(delimiter). To read this type of .csv file i used following connection string string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';"; As well as in the registry i specified (|) delimiter at following place: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text i defined "Format" = "Delimited(|)" and second C# application able to read .csv file in correct way but now the problem is that it screwed up my first C# application as it is using comma as seperater. Is there a way to define multiple custom delimiter under registry setting at following place HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text like Delimited("|",",") etc or some thing like that?? I tried that but it didn't work. My questions are : - how can my both C# application should work without effecting each other? As i said , one is having comma(,) as sepearter(delimiter) in .csv file and other is having (|) pipe as sepearter, how can my two different application can work at it's own without effecting each other? - Currently as i defined delimited(|) in above mentioned registry setting so it screwed up first application and my first application is NOT able to read .csv file (which has comma(,) as delimiter) - Is there a way to define Multiple delimiter in registry settings at above mentioned location at registry? I don't want to use scheme.ini file at all. Pls

    L E P R 4 Replies Last reply
    0
    • M montu3377

      Hi All, I have two C# windows application, both are reading .csv file and doing some processing, however there is one difference between both .csv file. One .csv file is using comma (,) as delimiter (separater) and other .csv file is using |(Pipe) character as delimiter (separater), so basically that is customized seperater. Both .csv file is used by my two different C# windows application. Now here is a problem. My first application used .csv file which has comma(,) as seperater and i am using provider as "Microsoft.Jet.OLEDB.4.0" to reading that file with following connectionstring: string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvfile.Directory.FullName + ";Extended Properties='text;HDR=Yes'"; As by default it's comma, so i don't have to do any changes in my registry to read this file, it's simple but problem came when i am using my other C# windows application. Second C# windows application is using other .csv file which has |(Pipe) character as seperater(delimiter). To read this type of .csv file i used following connection string string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';"; As well as in the registry i specified (|) delimiter at following place: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text i defined "Format" = "Delimited(|)" and second C# application able to read .csv file in correct way but now the problem is that it screwed up my first C# application as it is using comma as seperater. Is there a way to define multiple custom delimiter under registry setting at following place HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text like Delimited("|",",") etc or some thing like that?? I tried that but it didn't work. My questions are : - how can my both C# application should work without effecting each other? As i said , one is having comma(,) as sepearter(delimiter) in .csv file and other is having (|) pipe as sepearter, how can my two different application can work at it's own without effecting each other? - Currently as i defined delimited(|) in above mentioned registry setting so it screwed up first application and my first application is NOT able to read .csv file (which has comma(,) as delimiter) - Is there a way to define Multiple delimiter in registry settings at above mentioned location at registry? I don't want to use scheme.ini file at all. Pls

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      montu3377 wrote:

      delimiter under registry

      Do you have to use the registry? There are easier/better ways to accomplish this other than using a registry setting.

      Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here

      M 1 Reply Last reply
      0
      • L Lost User

        montu3377 wrote:

        delimiter under registry

        Do you have to use the registry? There are easier/better ways to accomplish this other than using a registry setting.

        Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here

        M Offline
        M Offline
        montu3377
        wrote on last edited by
        #3

        Hi, Can you tell me what are easier ways? I am using following code : //Taking connection using to .csv file string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';"; //assigning to oledbconnection string OleDbConnection conn = new OleDbConnection(textConnectionString); // Opening connection conn.Open(); //selecting rows from .csv file sql_select = "Select * from " + InputCSVFile.ToString().Trim() ; //Creates the data adapter OleDbDataAdapter obj_oledb_da = new OleDbDataAdapter(sql_select, conn); //Fills dataset with the records from CSV file obj_oledb_da.Fill(ds); As i have (|) pipe character in my .csv file , so i am specifying (|) pipe sepearter in registry setting otherwise i will NOT get correct parsed values. Pls. let me know if you have some other way rather than this way?? I am eager to seeing that. Thanks a lot for reply.

        L 1 Reply Last reply
        0
        • M montu3377

          Hi, Can you tell me what are easier ways? I am using following code : //Taking connection using to .csv file string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';"; //assigning to oledbconnection string OleDbConnection conn = new OleDbConnection(textConnectionString); // Opening connection conn.Open(); //selecting rows from .csv file sql_select = "Select * from " + InputCSVFile.ToString().Trim() ; //Creates the data adapter OleDbDataAdapter obj_oledb_da = new OleDbDataAdapter(sql_select, conn); //Fills dataset with the records from CSV file obj_oledb_da.Fill(ds); As i have (|) pipe character in my .csv file , so i am specifying (|) pipe sepearter in registry setting otherwise i will NOT get correct parsed values. Pls. let me know if you have some other way rather than this way?? I am eager to seeing that. Thanks a lot for reply.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          montu3377 wrote:

          way rather than this way

          Take a look at this article, A Fast CSV Reader[^] and see if that is fills your need. You can use whatever delimiter you want.

          Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Individuality is fine, as long as we do it together - F. Burns Help humanity, join the CodeProject grid computing team here

          1 Reply Last reply
          0
          • M montu3377

            Hi All, I have two C# windows application, both are reading .csv file and doing some processing, however there is one difference between both .csv file. One .csv file is using comma (,) as delimiter (separater) and other .csv file is using |(Pipe) character as delimiter (separater), so basically that is customized seperater. Both .csv file is used by my two different C# windows application. Now here is a problem. My first application used .csv file which has comma(,) as seperater and i am using provider as "Microsoft.Jet.OLEDB.4.0" to reading that file with following connectionstring: string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvfile.Directory.FullName + ";Extended Properties='text;HDR=Yes'"; As by default it's comma, so i don't have to do any changes in my registry to read this file, it's simple but problem came when i am using my other C# windows application. Second C# windows application is using other .csv file which has |(Pipe) character as seperater(delimiter). To read this type of .csv file i used following connection string string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';"; As well as in the registry i specified (|) delimiter at following place: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text i defined "Format" = "Delimited(|)" and second C# application able to read .csv file in correct way but now the problem is that it screwed up my first C# application as it is using comma as seperater. Is there a way to define multiple custom delimiter under registry setting at following place HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text like Delimited("|",",") etc or some thing like that?? I tried that but it didn't work. My questions are : - how can my both C# application should work without effecting each other? As i said , one is having comma(,) as sepearter(delimiter) in .csv file and other is having (|) pipe as sepearter, how can my two different application can work at it's own without effecting each other? - Currently as i defined delimited(|) in above mentioned registry setting so it screwed up first application and my first application is NOT able to read .csv file (which has comma(,) as delimiter) - Is there a way to define Multiple delimiter in registry settings at above mentioned location at registry? I don't want to use scheme.ini file at all. Pls

            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #5

            Is to use different extensions for your file types to determine whether a pipe or a comma is used as the delimiter.

            Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

            1 Reply Last reply
            0
            • M montu3377

              Hi All, I have two C# windows application, both are reading .csv file and doing some processing, however there is one difference between both .csv file. One .csv file is using comma (,) as delimiter (separater) and other .csv file is using |(Pipe) character as delimiter (separater), so basically that is customized seperater. Both .csv file is used by my two different C# windows application. Now here is a problem. My first application used .csv file which has comma(,) as seperater and i am using provider as "Microsoft.Jet.OLEDB.4.0" to reading that file with following connectionstring: string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvfile.Directory.FullName + ";Extended Properties='text;HDR=Yes'"; As by default it's comma, so i don't have to do any changes in my registry to read this file, it's simple but problem came when i am using my other C# windows application. Second C# windows application is using other .csv file which has |(Pipe) character as seperater(delimiter). To read this type of .csv file i used following connection string string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';"; As well as in the registry i specified (|) delimiter at following place: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text i defined "Format" = "Delimited(|)" and second C# application able to read .csv file in correct way but now the problem is that it screwed up my first C# application as it is using comma as seperater. Is there a way to define multiple custom delimiter under registry setting at following place HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text like Delimited("|",",") etc or some thing like that?? I tried that but it didn't work. My questions are : - how can my both C# application should work without effecting each other? As i said , one is having comma(,) as sepearter(delimiter) in .csv file and other is having (|) pipe as sepearter, how can my two different application can work at it's own without effecting each other? - Currently as i defined delimited(|) in above mentioned registry setting so it screwed up first application and my first application is NOT able to read .csv file (which has comma(,) as delimiter) - Is there a way to define Multiple delimiter in registry settings at above mentioned location at registry? I don't want to use scheme.ini file at all. Pls

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              I don't think I've ever heard of anyone using the Jet engine to read a CSV file. :confused: Most people just read and Split the lines.

              M 1 Reply Last reply
              0
              • P PIEBALDconsult

                I don't think I've ever heard of anyone using the Jet engine to read a CSV file. :confused: Most people just read and Split the lines.

                M Offline
                M Offline
                Matt Meyer
                wrote on last edited by
                #7

                Using Jet (or ACE) is pretty useful because you can use the ADO.Net classes to work with the data instead of manually parsing. It's especially useful for more complex CSVs that have "Excel-friendly" fields similar to

                "=""Value""""WithQuotes"""

                1 Reply Last reply
                0
                • M montu3377

                  Hi All, I have two C# windows application, both are reading .csv file and doing some processing, however there is one difference between both .csv file. One .csv file is using comma (,) as delimiter (separater) and other .csv file is using |(Pipe) character as delimiter (separater), so basically that is customized seperater. Both .csv file is used by my two different C# windows application. Now here is a problem. My first application used .csv file which has comma(,) as seperater and i am using provider as "Microsoft.Jet.OLEDB.4.0" to reading that file with following connectionstring: string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvfile.Directory.FullName + ";Extended Properties='text;HDR=Yes'"; As by default it's comma, so i don't have to do any changes in my registry to read this file, it's simple but problem came when i am using my other C# windows application. Second C# windows application is using other .csv file which has |(Pipe) character as seperater(delimiter). To read this type of .csv file i used following connection string string textConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\"" + StrInputCSVFile + "\";Extended Properties='text;HDR=No;FMT=Delimited';"; As well as in the registry i specified (|) delimiter at following place: HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text i defined "Format" = "Delimited(|)" and second C# application able to read .csv file in correct way but now the problem is that it screwed up my first C# application as it is using comma as seperater. Is there a way to define multiple custom delimiter under registry setting at following place HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Jet \ 4.0 \ Engines \ Text like Delimited("|",",") etc or some thing like that?? I tried that but it didn't work. My questions are : - how can my both C# application should work without effecting each other? As i said , one is having comma(,) as sepearter(delimiter) in .csv file and other is having (|) pipe as sepearter, how can my two different application can work at it's own without effecting each other? - Currently as i defined delimited(|) in above mentioned registry setting so it screwed up first application and my first application is NOT able to read .csv file (which has comma(,) as delimiter) - Is there a way to define Multiple delimiter in registry settings at above mentioned location at registry? I don't want to use scheme.ini file at all. Pls

                  R Offline
                  R Offline
                  Rod Kemp
                  wrote on last edited by
                  #8

                  If you want to continue using the Jet engine to read in your pipe delimited file then you are going to have to use a schema.ini file as the registry can only be use for a single delimiter value or, use the article Wes linked to and drop using the Jet engine.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups