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
  1. Home
  2. General Programming
  3. C#
  4. help with inport csv file to my C# program

help with inport csv file to my C# program

Scheduled Pinned Locked Moved C#
tutorialcsharpdatabasehelpquestion
10 Posts 9 Posters 2 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.
  • G Offline
    G Offline
    goldsoft
    wrote on last edited by
    #1

    hi i try to inport csv file to my database in my C# winform program. for example the csv file: code ,name ,price 101010,computer,200$ and i done this: char[] BI = { ',' }; string[] WI = TEMP.Split(BI); A = WI[0].Trim().ToString(); B = WI[1].Trim().ToString(); C = WI[2].Trim().ToString(); but what i can do if the name contain (,) ? for example code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv: code ,name ,price "101010","computer 12,200.00","200$" how to deal with this ?

    G T H D P 6 Replies Last reply
    0
    • G goldsoft

      hi i try to inport csv file to my database in my C# winform program. for example the csv file: code ,name ,price 101010,computer,200$ and i done this: char[] BI = { ',' }; string[] WI = TEMP.Split(BI); A = WI[0].Trim().ToString(); B = WI[1].Trim().ToString(); C = WI[2].Trim().ToString(); but what i can do if the name contain (,) ? for example code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv: code ,name ,price "101010","computer 12,200.00","200$" how to deal with this ?

      G Offline
      G Offline
      Goutam Patra
      wrote on last edited by
      #2

      Perhaps this link[^] will help you.

      P 1 Reply Last reply
      0
      • G goldsoft

        hi i try to inport csv file to my database in my C# winform program. for example the csv file: code ,name ,price 101010,computer,200$ and i done this: char[] BI = { ',' }; string[] WI = TEMP.Split(BI); A = WI[0].Trim().ToString(); B = WI[1].Trim().ToString(); C = WI[2].Trim().ToString(); but what i can do if the name contain (,) ? for example code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv: code ,name ,price "101010","computer 12,200.00","200$" how to deal with this ?

        T Offline
        T Offline
        thatraja
        wrote on last edited by
        #3

        Recently I have seen this thread[^] which will help you.

        thatraja |Chennai|India|


        Brainbench certifications
        Univotes are like kid's kisses don't reject it :-)
        Do what you want quickly because the Doomsday on 2012 :-)
        My childhood story

        1 Reply Last reply
        0
        • G goldsoft

          hi i try to inport csv file to my database in my C# winform program. for example the csv file: code ,name ,price 101010,computer,200$ and i done this: char[] BI = { ',' }; string[] WI = TEMP.Split(BI); A = WI[0].Trim().ToString(); B = WI[1].Trim().ToString(); C = WI[2].Trim().ToString(); but what i can do if the name contain (,) ? for example code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv: code ,name ,price "101010","computer 12,200.00","200$" how to deal with this ?

          H Offline
          H Offline
          Hiren solanki
          wrote on last edited by
          #4

          goldsoft wrote:

          code ,name ,price "101010","computer 12,200.00","200$"

          For this there's a solution, You can use regex to use. follow the step 1. Replace the ',' Char inside "abc,xyz" with some Character not conflicted with CSV delimeter, Say @, using Regex. 2. Now you will get exact split in three words, Once splitted further Replace the '@' with ',' in Splitted string.

          goldsoft wrote:

          code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv:

          For this I don't think of any Intelligent detection.

          Regards, Hiren.

          My Recent Article: - Way to know which control have raised PostBack
          My Recent Tip/Trick: - Remove HTML Tag, get plain Text

          1 Reply Last reply
          0
          • G goldsoft

            hi i try to inport csv file to my database in my C# winform program. for example the csv file: code ,name ,price 101010,computer,200$ and i done this: char[] BI = { ',' }; string[] WI = TEMP.Split(BI); A = WI[0].Trim().ToString(); B = WI[1].Trim().ToString(); C = WI[2].Trim().ToString(); but what i can do if the name contain (,) ? for example code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv: code ,name ,price "101010","computer 12,200.00","200$" how to deal with this ?

            D Offline
            D Offline
            Dan Mos
            wrote on last edited by
            #5

            Why not treat the csv as a db. You could use Jet OleDb, or odbc. Details here. :)

            I used to think.... Finally I realized it's no good.

            1 Reply Last reply
            0
            • G goldsoft

              hi i try to inport csv file to my database in my C# winform program. for example the csv file: code ,name ,price 101010,computer,200$ and i done this: char[] BI = { ',' }; string[] WI = TEMP.Split(BI); A = WI[0].Trim().ToString(); B = WI[1].Trim().ToString(); C = WI[2].Trim().ToString(); but what i can do if the name contain (,) ? for example code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv: code ,name ,price "101010","computer 12,200.00","200$" how to deal with this ?

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

              Yeah, what they said, especially Rive :thumbsup: .

              goldsoft wrote:

              WI[0].Trim().ToString();

              You don't need the ToString.

              1 Reply Last reply
              0
              • G Goutam Patra

                Perhaps this link[^] will help you.

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

                Thank you. :thumbsup:

                L R 2 Replies Last reply
                0
                • P PIEBALDconsult

                  Thank you. :thumbsup:

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  10! :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

                  1 Reply Last reply
                  0
                  • G goldsoft

                    hi i try to inport csv file to my database in my C# winform program. for example the csv file: code ,name ,price 101010,computer,200$ and i done this: char[] BI = { ',' }; string[] WI = TEMP.Split(BI); A = WI[0].Trim().ToString(); B = WI[1].Trim().ToString(); C = WI[2].Trim().ToString(); but what i can do if the name contain (,) ? for example code ,name ,price 101010,computer 12,200.00,200$ if i get this type of csv: code ,name ,price "101010","computer 12,200.00","200$" how to deal with this ?

                    _ Offline
                    _ Offline
                    _Erik_
                    wrote on last edited by
                    #9

                    Could be a deja vu, but I think I have seen this question in random forums (or a very similar one) every two weeks in the last months. Please, write csv in the search text box at the top of this forum. Maybe you'll get what you need.

                    1 Reply Last reply
                    0
                    • P PIEBALDconsult

                      Thank you. :thumbsup:

                      R Offline
                      R Offline
                      Roger Wright
                      wrote on last edited by
                      #10

                      Well done! :-D You should be seeing a small spike in your reputation score today...

                      Will Rogers never met me.

                      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