Best Way to Read .csv File?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TC

    Best Way to Read .csv File?

    Hey All,

    I have to read .csv files and display them in a DataGridView.

    Currently, I'm dumping the data into a DataTable but it's causing problems
    because the engine is automatically converting / deleting material.

    I cannot use a .ini file because the .csv files could be called anything and
    come from any folder (i.e. it's a 'FileOpen' dialog necessity).

    What is the best / quickest way to read .csv files such that the data is not
    changed or is understood as strings?

    Thanks,

    TC


  • TC

    #2
    Re: Best Way to Read .csv File?

    Hey All,

    It appears that one has to read the file using StreamReader, parse the lines
    using the appropriate delimeter and then pump in the columns and rows.

    The above worked for me.



    "TC" <getmyemails2@y ahoo.comwrote in message
    news:%23hIcIaZ$ IHA.1224@TK2MSF TNGP02.phx.gbl. ..
    Hey All,
    >
    I have to read .csv files and display them in a DataGridView.
    >
    Currently, I'm dumping the data into a DataTable but it's causing problems
    because the engine is automatically converting / deleting material.
    >
    I cannot use a .ini file because the .csv files could be called anything
    and come from any folder (i.e. it's a 'FileOpen' dialog necessity).
    >
    What is the best / quickest way to read .csv files such that the data is
    not changed or is understood as strings?
    >
    Thanks,
    >
    TC
    >

    Comment

    • Cor Ligthert [MVP]

      #3
      Re: Best Way to Read .csv File?

      Not the general best way.

      As your CSV file is showable in Excel the you would be able to make dataset
      from it (there is a property to distinct numbers from text).

      Just for others thinking that what you have choosen is in general the best
      way.
      (Probably I had done it in your situation the same as you)

      Cor

      "TC" <getmyemails2@y ahoo.comschreef in bericht
      news:%23Zx8g9d$ IHA.6132@TK2MSF TNGP04.phx.gbl. ..
      Hey All,
      >
      It appears that one has to read the file using StreamReader, parse the
      lines using the appropriate delimeter and then pump in the columns and
      rows.
      >
      The above worked for me.
      >
      >
      >
      "TC" <getmyemails2@y ahoo.comwrote in message
      news:%23hIcIaZ$ IHA.1224@TK2MSF TNGP02.phx.gbl. ..
      >Hey All,
      >>
      >I have to read .csv files and display them in a DataGridView.
      >>
      >Currently, I'm dumping the data into a DataTable but it's causing
      >problems because the engine is automatically converting / deleting
      >material.
      >>
      >I cannot use a .ini file because the .csv files could be called anything
      >and come from any folder (i.e. it's a 'FileOpen' dialog necessity).
      >>
      >What is the best / quickest way to read .csv files such that the data is
      >not changed or is understood as strings?
      >>
      >Thanks,
      >>
      >TC
      >>
      >
      >

      Comment

      • Bill McCarthy

        #4
        Re: Best Way to Read .csv File?

        Hi TC,

        The TextFieldParser does a lot of that for you.


        "TC" <getmyemails2@y ahoo.comwrote in message
        news:%23Zx8g9d$ IHA.6132@TK2MSF TNGP04.phx.gbl. ..
        Hey All,
        >
        It appears that one has to read the file using StreamReader, parse the
        lines using the appropriate delimeter and then pump in the columns and
        rows.
        >
        The above worked for me.
        >
        >
        >
        "TC" <getmyemails2@y ahoo.comwrote in message
        news:%23hIcIaZ$ IHA.1224@TK2MSF TNGP02.phx.gbl. ..
        >Hey All,
        >>
        >I have to read .csv files and display them in a DataGridView.
        >>
        >Currently, I'm dumping the data into a DataTable but it's causing
        >problems because the engine is automatically converting / deleting
        >material.
        >>
        >I cannot use a .ini file because the .csv files could be called anything
        >and come from any folder (i.e. it's a 'FileOpen' dialog necessity).
        >>
        >What is the best / quickest way to read .csv files such that the data is
        >not changed or is understood as strings?
        >>
        >Thanks,
        >>
        >TC
        >>
        >
        >

        Comment

        • Peter Gibbons

          #5
          Re: Best Way to Read .csv File?

          Bill McCarthy wrote:
          Hi TC,
          >
          The TextFieldParser does a lot of that for you.
          >
          >
          Hello TC,

          I also had good results with TextFieldParser . Beware of encodings when
          messing with text files. Are you using UFT8?

          Regards,

          Peter

          Comment

          Working...