August 24, 2015 at 8:30 am
Hi,
I am reading a file in a script task and inserting data in database. Using the below code.
char delimiter = '|';
StreamReader sr = new StreamReader(fileName);
while (sr.Peek() != -1)
{
SqlParameter[] Params = new SqlParameter[14];
if(!sr.ReadLine().Contains("ErrorHeader"))
{
string[] errorRow = sr.ReadLine().Split(delimiter);
string action = errorRow[3].Substring(2, 1);
string IdNo = errorRow[3].Substring(3, 10);
}
}
sr.DiscardBufferedData();
sr.Close();
sr.Dispose();
It reads some random lines and will give null pointer at sr.ReadLine().Split(delimiter);
Sometime it will process 3 sometimes 4 lines .May be I am missing something. Please suggest.
August 24, 2015 at 12:37 pm
Hi
I prefer ReadLine method until is null returned instead of Peek, please try:
String FileLine
while ((FileLine = sr.ReadLine()) != null)
{
...
}
Br.
Mike
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy