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;i van
mauricio;334761 4603;tr****@yah oo.com;1984-06-04;M;;;milano;C O;politecnico #
ingegneria;;;
106934;004008;r osso;carin;;ca* *****@student.u u.se;1982-04-03;F;;;;SE;bocc oni;;;
106935;003785;r osso;luca;;lu** *********@hotma il.it;1984-03-10;M;;;;IE;iulm
- PR;;;
Riga assumes the following values:
"\t106933;;ross o;ivan
mauricio;334761 4603;tr****@yah oo.com;1984-06-04;M;;;milano;C O;politecnico #
ingegneria;;; "
"\t106934;;ross o;ivan
mauricio;334761 4603;tr****@yah oo.com;1984-06-04;M;;;milano;C O;politecnico #
ingegneria;;; "
"\t106935;;ross o;ivan
mauricio;334761 4603;tr****@yah oo.com;1984-06-04;M;;;milano;C O;politecnico #
ingegneria;;; "
StreamReader.Re adLine() 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.Pe rformStep();
StringBuilder query = new StringBuilder(" INSERT INTO TESSERE
VALUES(");
StringBuilder query2 = new StringBuilder(" DELETE FROM
TESSERE WHERE Tessera=");
// query building
try
{
OleDbCommand cmd2 = new OleDbCommand(qu ery2.ToString() ,
conn);
cmd2.ExecuteRea der();
OleDbCommand cmd = new OleDbCommand(qu ery.ToString(),
conn);
cmd.ExecuteRead er();
query2 = null;
query = null;
cmd = null;
cmd2 = null;
}
catch (System.Data.Ol eDb.OleDbExcept ion 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 8503
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**@discussio ns.microsoft.co mwrote in message
news:42******** *************** ***********@mic rosoft.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;i van
mauricio;334761 4603;tr****@yah oo.com;1984-06-04;M;;;milano;C O;politecnico
#
ingegneria;;;
106934;004008;r osso;carin;;ca* *****@student.u u.se;1982-04-03;F;;;;SE;bocc oni;;;
106935;003785;r osso;luca;;lu** *********@hotma il.it;1984-03-10;M;;;;IE;iulm
- PR;;;
Riga assumes the following values:
"\t106933;;ross o;ivan
mauricio;334761 4603;tr****@yah oo.com;1984-06-04;M;;;milano;C O;politecnico
#
ingegneria;;; "
"\t106934;;ross o;ivan
mauricio;334761 4603;tr****@yah oo.com;1984-06-04;M;;;milano;C O;politecnico
#
ingegneria;;; "
"\t106935;;ross o;ivan
mauricio;334761 4603;tr****@yah oo.com;1984-06-04;M;;;milano;C O;politecnico
#
ingegneria;;; "
StreamReader.Re adLine() 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.Pe rformStep();
StringBuilder query = new StringBuilder(" INSERT INTO
TESSERE
VALUES(");
StringBuilder query2 = new StringBuilder(" DELETE FROM
TESSERE WHERE Tessera=");
// query building
try
{
OleDbCommand cmd2 = new OleDbCommand(qu ery2.ToString() ,
conn);
cmd2.ExecuteRea der();
OleDbCommand cmd = new OleDbCommand(qu ery.ToString(),
conn);
cmd.ExecuteRead er();
query2 = null;
query = null;
cmd = null;
cmd2 = null;
}
catch (System.Data.Ol eDb.OleDbExcept ion 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() the string returned by readline() on the file.
The following code snippet works for me:
tokens = "one,two,three,four".Split(",")
for each token in tokens
response.write("<td>"+token+"</td>")
|
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 like this...
while(!done)
{
idleTimer.Start();
response = streamReader.ReadLine();
idleTimer.Stop();
....
|
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);
string sRowText;
while ((sRowText = oStreamFile.ReadLine()) !=null)
|
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 server is on one line (\r\n at end) and
is formed as - each of
which is seperated by a space. Arguments with spaces in them are enclosed in
quotations.
So, I'm able to open a connection to the server. When I send a message to
|
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 file. My problem is that on
subsequent reads, the starting position is not correct.
I have tried many different ways to increment the file
position value, but I cannot get it to work so that on the
next read, the read starts at the correct...
| |
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 (info=streamReader.ReadLine) another time,
the program hangs. Most likely since the SMTP server has no other responses
to post. Is there a way to make the streamreader time out if there is no
other info?
BTW, the only code not posted is ConnectSocket...it...
|
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 garbage under ReadLine method. Does
anybody have any idea on this issue?
Thanks for your attention and kindly help!
Regards,
|
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 if the Seek
never worked.
Shouldn't sString1 and sString2 each contain the first line of the file?
To fix this (as in Main2), I need to create a new reader. Is this
documented behavior, or is this a bug??
|
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 line Count of Sr
}
i just want to get a count of sr.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |