reading text file issue

Discussion in 'ASP .Net' started by John, Jun 2, 2006.

  1. John

    John Guest

    I have a process that reads a text file then uploads the data into a
    database table. The text file has 10 lines at the end of the file that are
    blank BUT it appears that the enter key or space bar was hit so the code
    thinks its lines of data and this is causing my process to fail. How can I
    skip those lines and have my process continue and complete successfully?
    this file is generated automatically for uploading and then supplied to me
    for the upload process
     
    John, Jun 2, 2006
    #1
    1. Advertising

  2. How are you reading the file? StreamReader?

    I use this pattern for line by line type of insert. It can be used to prep a
    bulk load file. NOTE: if you are on SQL Server and set up a bulk load, you
    can set it up to ignore a number of errors.

    string line;

    while(null != (line = reader.ReadLine()))
    {
    if(line.Trim().Length != 0)
    {
    ProcessLine(line);
    }
    }


    --
    Gregory A. Beamer

    *************************************************
    Think Outside the Box!
    *************************************************
    "John" <> wrote in message
    news:ek0%...
    >I have a process that reads a text file then uploads the data into a
    >database table. The text file has 10 lines at the end of the file that are
    >blank BUT it appears that the enter key or space bar was hit so the code
    >thinks its lines of data and this is causing my process to fail. How can I
    >skip those lines and have my process continue and complete successfully?
    >this file is generated automatically for uploading and then supplied to me
    >for the upload process
    >
     
    Cowboy \(Gregory A. Beamer\), Jun 2, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darrel
    Replies:
    3
    Views:
    688
    Kevin Spencer
    Nov 11, 2004
  2. Replies:
    0
    Views:
    798
  3. Replies:
    1
    Views:
    459
    Keith Thompson
    Apr 12, 2005
  4. Lionel
    Replies:
    22
    Views:
    672
    Steve Holden
    Feb 3, 2009
  5. Robin Wenger
    Replies:
    191
    Views:
    3,273
Loading...

Share This Page