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 2 8437
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andy Mee |
last post by:
Hello one and all,
I'm developing an Asp.NET system to take a CSV file uploaded via the web,
parse it, and insert the values into an SQL database. My sticking point
comes when I try to split()...
|
by: redneon |
last post by:
I have a program which is constantly reading from a stream and what I'm
wanting to do is, if the stream hasn't sent anything after a certain amount
of time then do something. I've tried doing this...
|
by: Tarren |
last post by:
Hi:
Question which might have something to do with encoding?
I have a text file and I use the following code to iterate through.
StreamReader oStreamFile = new StreamReader(sFileName);
...
|
by: JoKur |
last post by:
Hello,
First let me tell you that I'm very new to C# and learning as I go. I'm
trying to write a client application to communicate with a server (that I
didn't write). Each message from the...
|
by: Eric |
last post by:
I am trying to save the "last read" position of a file
using a StreamReader object. I am reading the lines of
the file using StreamReader.ReadLine and then saving the
current position in the...
|
by: Rob T |
last post by:
Hi, I have a simple little program that I'm going to use to access our SMTP
server. The below code works perfectly fine, but my question is if I were
to try to execute the last line...
|
by: James Wong |
last post by:
Dear all,
I'm using StreamReader to read a text file containing BIG-5 data and found
that no matter which encoding method in StreamReader's construction
parameter, the BIG-5 contents become...
|
by: Joan Reddy |
last post by:
Can anyone tell me why this code doesn't work for setting the pointer to the
begining of a file stream?
This is driving me crazy.
At the end of Main1, sString2 is the second line of the file, as...
|
by: somequestion |
last post by:
Question 1.
i am using StreamReader Class like this...
string str = string.Empty;
StreamReader sr = new StreamReader(fsIn,Encoding.Default)
while ((str = sr.ReadLine()) != null)
{
// wanna get...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |