reading text file issue

J

John

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
 
C

Cowboy \(Gregory A. Beamer\)

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!
*************************************************
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top