reading text files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fazan
    New Member
    • Jan 2007
    • 5

    #1

    reading text files

    Hi,
    I have a text file that needs to be exported to a sql server table. the text file is something similar to this,
    -------------
    * 01.08.2007

    06:00 go to work
    12:00 lunch
    17:00 go home
    19:00 dinner
    21:00 go to bed
    09:00 go to leisure centre
    --------------

    I need to pull these details to a db table which has columns Date, Time, Description. The first record imported will be Date. A new record begins when a new time delimiter appears in the text file. A new date begins if a record falls after 06:00.
    Does anyone have idea how to do this using vb.net?
  • swheat
    New Member
    • Nov 2007
    • 3

    #2
    hello,

    If possible you need to structure your data better. Search the internet for "comma delimited".
    You need to include the date on each row:
    "date","time"," activity","some thing else"
    "11-10-2007","8:00am", "have a beer","go back to sleep"

    You should also look into String.Split. See msdn2.microsoft .com for examples.


    Hope that helps you.
    Sam

    Comment

    • Fazan
      New Member
      • Jan 2007
      • 5

      #3
      yeah if I structure the data I can be able to do it, but the thing is the text file should be in that structure, I need to find a way to pull the data to db table

      Fazan

      Comment

      • swheat
        New Member
        • Nov 2007
        • 3

        #4
        Originally posted by Fazan
        yeah if I structure the data I can be able to do it, but the thing is the text file should be in that structure, I need to find a way to pull the data to db table

        Fazan
        Well, you need some way to delimit the data.
        Read each line character by charater. Using what you posted above, if the first char is a "*", followed by a space, followed by a value which successfully converts to datetime, you have your date id.
        Read the next line.
        If the chars before the first space convert to a date time and there is a space followed by some text followed by end-of-line, you have a row.
        There are many examples on the internet, here is one i found in 5 seconds that shows basic file io:
        http://www.codeproject .com/useritems/LineCounter.asp

        Comment

        Working...