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 8435
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: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |