By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,198 Members | 897 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,198 IT Pros & Developers. It's quick & easy.

StreamReader.ReadLine()

P: n/a
I have a big problem with streamreader ReadLine()! I read from a long text
files about 13k lines, than I encounter a problem: ReadLine() is not anymore
able to go on! I have a string whose name is riga, where I put the return
value of Readline(), and this is what happens, when I read these three lines:

106933;;rosso;ivan
mauricio;3347614603;tr****@yahoo.com;1984-06-04;M;;;milano;CO;politecnico #
ingegneria;;;
106934;004008;rosso;carin;;ca******@student.uu.se; 1982-04-03;F;;;;SE;bocconi;;;
106935;003785;rosso;luca;;lu***********@hotmail.it ;1984-03-10;M;;;;IE;iulm
- PR;;;

Riga assumes the following values:
"\t106933;;rosso;ivan
mauricio;3347614603;tr****@yahoo.com;1984-06-04;M;;;milano;CO;politecnico #
ingegneria;;; "

"\t106934;;rosso;ivan
mauricio;3347614603;tr****@yahoo.com;1984-06-04;M;;;milano;CO;politecnico #
ingegneria;;; "

"\t106935;;rosso;ivan
mauricio;3347614603;tr****@yahoo.com;1984-06-04;M;;;milano;CO;politecnico #
ingegneria;;; "

StreamReader.ReadLine() reads only the first part of the line, the
number...why? here is the code:

vwhile ((riga = flusso.ReadLine()) != null)
{
int iter = 0;
string[] campi = riga.Split(';');
progressBar1.PerformStep();
StringBuilder query = new StringBuilder("INSERT INTO TESSERE
VALUES(");
StringBuilder query2 = new StringBuilder("DELETE FROM
TESSERE WHERE Tessera=");
// query building

try
{
OleDbCommand cmd2 = new OleDbCommand(query2.ToString(),
conn);
cmd2.ExecuteReader();
OleDbCommand cmd = new OleDbCommand(query.ToString(),
conn);
cmd.ExecuteReader();
query2 = null;
query = null;
cmd = null;
cmd2 = null;
}
catch (System.Data.OleDb.OleDbException e)
{
continue;
}
}

The line where this happen is a line which raises an exception because it is
not in the right format(the following ones, instead, are in the right format
for the query to be built) but, in the text files, there are several lines
before where it happens, and the program is able to go on to the following
lines without problem! I can't see why here the ReadLine() stops...

Thanks

Eddy
Oct 4 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Eddy wrote:
I have a big problem with streamreader ReadLine()! I read from a long text
files about 13k lines, than I encounter a problem: ReadLine() is not anymore
able to go on! I have a string whose name is riga, where I put the return
value of Readline(), and this is what happens, when I read these three lines:
Can you write a short but complete program that demonstrates the
problem? See http://www.pobox.com/~skeet/csharp/complete.html for what
I mean by that.

I suspect you'll find that your file has a rogue carriage return or
line feed in the line in question, to be honest - but when we can
reproduce your problem, we'll know for sure.

Jon

Oct 4 '06 #2

P: n/a
You mentioned 'long text' so is it possible to use only Read() instead of
Readline() to form your string?
http://msdn2.microsoft.com/en-us/lib...ader.read.aspx

chanmm

"Eddy" <Ed**@discussions.microsoft.comwrote in message
news:42**********************************@microsof t.com...
>I have a big problem with streamreader ReadLine()! I read from a long text
files about 13k lines, than I encounter a problem: ReadLine() is not
anymore
able to go on! I have a string whose name is riga, where I put the return
value of Readline(), and this is what happens, when I read these three
lines:

106933;;rosso;ivan
mauricio;3347614603;tr****@yahoo.com;1984-06-04;M;;;milano;CO;politecnico
#
ingegneria;;;
106934;004008;rosso;carin;;ca******@student.uu.se; 1982-04-03;F;;;;SE;bocconi;;;
106935;003785;rosso;luca;;lu***********@hotmail.it ;1984-03-10;M;;;;IE;iulm
- PR;;;

Riga assumes the following values:
"\t106933;;rosso;ivan
mauricio;3347614603;tr****@yahoo.com;1984-06-04;M;;;milano;CO;politecnico
#
ingegneria;;; "

"\t106934;;rosso;ivan
mauricio;3347614603;tr****@yahoo.com;1984-06-04;M;;;milano;CO;politecnico
#
ingegneria;;; "

"\t106935;;rosso;ivan
mauricio;3347614603;tr****@yahoo.com;1984-06-04;M;;;milano;CO;politecnico
#
ingegneria;;; "

StreamReader.ReadLine() reads only the first part of the line, the
number...why? here is the code:

vwhile ((riga = flusso.ReadLine()) != null)
{
int iter = 0;
string[] campi = riga.Split(';');
progressBar1.PerformStep();
StringBuilder query = new StringBuilder("INSERT INTO
TESSERE
VALUES(");
StringBuilder query2 = new StringBuilder("DELETE FROM
TESSERE WHERE Tessera=");
// query building

try
{
OleDbCommand cmd2 = new OleDbCommand(query2.ToString(),
conn);
cmd2.ExecuteReader();
OleDbCommand cmd = new OleDbCommand(query.ToString(),
conn);
cmd.ExecuteReader();
query2 = null;
query = null;
cmd = null;
cmd2 = null;
}
catch (System.Data.OleDb.OleDbException e)
{
continue;
}
}

The line where this happen is a line which raises an exception because it
is
not in the right format(the following ones, instead, are in the right
format
for the query to be built) but, in the text files, there are several lines
before where it happens, and the program is able to go on to the following
lines without problem! I can't see why here the ReadLine() stops...

Thanks

Eddy

Oct 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.