manipulating files with ado.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher Nigro
    New Member
    • Jul 2010
    • 53

    #16
    Hi,

    My previous post still holds true: it's not the extention of the file that is problematic, but the structure of the contents. If the real CSV file is formatted the same as the text file example, you cannot query it with ADO.NET: the data is not tabular. You will have to read the file with a StreamReader or something and manipulate it programatically .

    Comment

    • dougancil
      Contributor
      • Apr 2010
      • 347

      #17
      Chris,

      Are there any good tutorials on using StreamReader or how to use it properly? I've googled it and can't really find any good information.

      Thank you,

      Doug

      Comment

      • Christopher Nigro
        New Member
        • Jul 2010
        • 53

        #18
        A StreamReader isn't all that complicated. For anything in .NET, I usually go right to the class definition first:
        Implements a TextReader that reads characters from a byte stream in a particular encoding.


        If you look at the available methods, you are really only ever going to be interested in the read methods:
        Read()
        Read(Char[], Int32, Int32)
        ReadBlock
        ReadLine
        ReadToEnd

        Each one of those provides an example. What, in particular, is not clear to you?

        Comment

        • dougancil
          Contributor
          • Apr 2010
          • 347

          #19
          Chris,

          Also when looking at the .csv file, it does appear that it's formatted correctly for a .csv file, but the data just replicates in a few places. I just want to make sure that I'm approaching this problem the best way possible.
          Thank you

          Doug

          Comment

          • Christopher Nigro
            New Member
            • Jul 2010
            • 53

            #20
            Originally posted by dougancil
            Chris,

            Also when looking at the .csv file, it does appear that it's formatted correctly for a .csv file, but the data just replicates in a few places. I just want to make sure that I'm approaching this problem the best way possible.
            Thank you

            Doug
            Can you post a few lines of the CSV file?

            Comment

            • Christopher Nigro
              New Member
              • Jul 2010
              • 53

              #21
              Yup, you have to forget about ADO.NET for this and use the StreamReader get it into a string array and then parse that array for what you are looking for. That really isn't a CSV file that you have there.

              Comment

              • dougancil
                Contributor
                • Apr 2010
                • 347

                #22
                So then the best place to call the StreamReader would be after the file was uploaded but before the sql query was ran and I could write that as a private function, correct?

                Comment

                • Christopher Nigro
                  New Member
                  • Jul 2010
                  • 53

                  #23
                  Yes, that sounds like a plan.

                  Comment

                  • dougancil
                    Contributor
                    • Apr 2010
                    • 347

                    #24
                    Ok so one other question is, I can still use regex once I've stored the datafile as a string correct? and just parse my information out of the string?

                    Comment

                    • Christopher Nigro
                      New Member
                      • Jul 2010
                      • 53

                      #25
                      Sure: regular expressions operate on strings and you have string data.

                      Comment

                      • dougancil
                        Contributor
                        • Apr 2010
                        • 347

                        #26
                        Chris,

                        I had an idea ... what about making this a datatable instead, since I have to parse out the information that I don't need. Because the file will be virtually the same every time, including the fields, I could set this up one time, parse out the data that I don't need and post the updated information to the SQL database. Will that work?

                        Comment

                        • Christopher Nigro
                          New Member
                          • Jul 2010
                          • 53

                          #27
                          Originally posted by dougancil
                          Chris,

                          I had an idea ... what about making this a datatable instead, since I have to parse out the information that I don't need. Because the file will be virtually the same every time, including the fields, I could set this up one time, parse out the data that I don't need and post the updated information to the SQL database. Will that work?
                          Hi Doug,

                          Sure, that's one way to go about it.

                          Comment

                          Working...