473,513 Members | 2,537 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data reader help!



Hi all.. i have another problem! The Read() method is supposed to
read through all the rows one by one untill no row is left to be
read... but not in my case.. after mySqlDataReader.Read() returns
true first time and gives the value in nout. etc.. it works fine, i
mean it executes fine the first time but when again it comes to the
while statement , " mySqlDataReader.Read()" is false whereas its
supposed to be true .. i checked if values are being read, by the
following code:

while(mySqlDataReader.Read())
{
string
nout=System.Convert.ToString(mySqlDataReader["Outbreak"]);
MessageBox.Show(nout);
}
but when writen as below, its making me crazy... i can do it with the
dataset but wanted to use datareader. plz help if u know how to
overcome it
while(mySqlDataReader.Read())
{

string nout=System.Convert.ToString(mySqlDataReader["Outbreak"]);
MessageBox.Show(nout);
for(int ii=0;ii<=rowcount;ii++) //iterate through the dataset or rows
{
string pout=System.Convert.ToString(ds.Tables["Patients"].Rows[ii]
["OutbreakDisease"]);
if(pout==null)
{
break;
}
else if (pout==nout)
{
if (diseases[0]==null)
{
diseases[count]=pout;
count=count+1;
}

else
{
for(int bi=0;bi<count;bi++)
{
if (diseases[bi]==pout)
{

break;
}
else
{
diseases[count]=pout;
count=count+1;
}
}
}

else if (pout!=nout)
{
continue;
}

}
}
msg=diseases[0]+diseases[1]+" are on outbreak";
MessageBox.Show(msg,"ALERT",MessageBoxButtons.OK,M essageBoxIcon.Information);
mySqlDataReader.Close();

conn1.Close();
}
catch (Exception ex)
{

Apr 2 '07 #1
3 2336
Shum,

Can you attach a compilable piece of code? I can't get VS to make heads
or tails of what you posted.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Shum" <sh******@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
>

Hi all.. i have another problem! The Read() method is supposed to
read through all the rows one by one untill no row is left to be
read... but not in my case.. after mySqlDataReader.Read() returns
true first time and gives the value in nout. etc.. it works fine, i
mean it executes fine the first time but when again it comes to the
while statement , " mySqlDataReader.Read()" is false whereas its
supposed to be true .. i checked if values are being read, by the
following code:

while(mySqlDataReader.Read())
{
string
nout=System.Convert.ToString(mySqlDataReader["Outbreak"]);
MessageBox.Show(nout);
}
but when writen as below, its making me crazy... i can do it with the
dataset but wanted to use datareader. plz help if u know how to
overcome it
while(mySqlDataReader.Read())
{

string nout=System.Convert.ToString(mySqlDataReader["Outbreak"]);
MessageBox.Show(nout);
for(int ii=0;ii<=rowcount;ii++) //iterate through the dataset or rows
{
string pout=System.Convert.ToString(ds.Tables["Patients"].Rows[ii]
["OutbreakDisease"]);
if(pout==null)
{
break;
}
else if (pout==nout)
{
if (diseases[0]==null)
{
diseases[count]=pout;
count=count+1;
}

else
{
for(int bi=0;bi<count;bi++)
{
if (diseases[bi]==pout)
{

break;
}
else
{
diseases[count]=pout;
count=count+1;
}
}
}

else if (pout!=nout)
{
continue;
}

}
}
msg=diseases[0]+diseases[1]+" are on outbreak";
MessageBox.Show(msg,"ALERT",MessageBoxButtons.OK,M essageBoxIcon.Information);
mySqlDataReader.Close();

conn1.Close();
}
catch (Exception ex)
{

Apr 2 '07 #2


That's some ugly code dude.

Make sure you not confusing .Read() with .NextResult().
You can download a complete DataReader example at:

5/24/2006
Custom Objects/Collections and Tiered Development
http://sholliday.spaces.live.com/blog/

And try to create an object which has placeholders for you values.
Then return that object.

Then do your biz rules/ string making.

public Class MyReturnObject
{
public string Nout
public string Pout
public MyCollection Diseases
}

somethikng like that.

your code is a hodgepodge mess of business rules and data access logic.

"Shum" <sh******@gmail.comwrote in message
news:11**********************@n76g2000hsh.googlegr oups.com...
>

Hi all.. i have another problem! The Read() method is supposed to
read through all the rows one by one untill no row is left to be
read... but not in my case.. after mySqlDataReader.Read() returns
true first time and gives the value in nout. etc.. it works fine, i
mean it executes fine the first time but when again it comes to the
while statement , " mySqlDataReader.Read()" is false whereas its
supposed to be true .. i checked if values are being read, by the
following code:

while(mySqlDataReader.Read())
{
string
nout=System.Convert.ToString(mySqlDataReader["Outbreak"]);
MessageBox.Show(nout);
}
but when writen as below, its making me crazy... i can do it with the
dataset but wanted to use datareader. plz help if u know how to
overcome it
while(mySqlDataReader.Read())
{

string nout=System.Convert.ToString(mySqlDataReader["Outbreak"]);
MessageBox.Show(nout);
for(int ii=0;ii<=rowcount;ii++) //iterate through the dataset or rows
{
string pout=System.Convert.ToString(ds.Tables["Patients"].Rows[ii]
["OutbreakDisease"]);
if(pout==null)
{
break;
}
else if (pout==nout)
{
if (diseases[0]==null)
{
diseases[count]=pout;
count=count+1;
}

else
{
for(int bi=0;bi<count;bi++)
{
if (diseases[bi]==pout)
{

break;
}
else
{
diseases[count]=pout;
count=count+1;
}
}
}

else if (pout!=nout)
{
continue;
}

}
}
msg=diseases[0]+diseases[1]+" are on outbreak";
MessageBox.Show(msg,"ALERT",MessageBoxButtons.OK,M essageBoxIcon.Information)
;
>

mySqlDataReader.Close();

conn1.Close();
}
catch (Exception ex)
{

Apr 2 '07 #3
:) yea i know its a total mess.. but i resolved my problem.
thanks guys

Apr 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1433
by: Stephen | last post by:
I'm having terrible trouble working out where I have gone wrong in my code below. In the data layer I have two methods and i'm basically returning a command and using it and then returning a reader. Unfortunately i'm getting the following error on the line: reader = cmdLogin.ExecuteReader(); Error Message: - Procedure 'LoginValidation'...
1
2109
by: Stephen | last post by:
I'm having terrible trouble working out where I have gone wrong in my code below. In the data layer I have two methods and i'm basically returning a command and using it and then returning a reader. Unfortunately i'm getting the following error on the line: reader = cmdLogin.ExecuteReader(); Error Message: - Procedure 'LoginValidation'...
1
1254
by: Troy | last post by:
Hello, I'd like to pass data between two pages but unable to get code to work. Code is below and any help is appreciated: ********************************************************************** 'Page1.aspx <%@ import namespace="System.Data" %> <%@ import namespace="System.Data.sqlclient" %>
2
6533
by: Robert Smith jr. | last post by:
Hello, Please pardon my newbie question ... I am building an ASP.NET page that displays a recordset with a Delete statement enabled (this all works fine). I want to Insert the current row *that is going to be deleted* into another table, before the original data is deleted. I am trying to use the RowDeleting method to call an Update...
4
1724
by: Ram | last post by:
I am using ADO.Net data reader to retrieve data from main frame. I am getting timestamp which is 26 (yyyy-mm-dd hh- mm-ss.123456) bytes as sqltimestamp data type. I am using data reader to retrieve this values and when i get it from data reader it is coverting as (yyyy-mm-dd hh-mm-ss AM or PM) and drops milliseconds. If any one of you come...
2
7525
by: Joe | last post by:
Anyone can suggest the best method of reading XML and adding data to ListView? Here is the xml data structure:: <xml> <site> <url>http://www.yahoo.com</url> <lastupdate></lastupdate> <check>1</check>
0
1184
by: Crazy Cat | last post by:
In the following code I retrieve data from a stored procedure that returns multiple resultsets (the results of the stored procedure have been stored in a datareader called reader). On each iteration a tab page is added to a tab control and a datagridview is created on that the tab page. In the first iteration I can set all the values with no...
1
2497
by: Tea | last post by:
Please help me ! My data in Microsoft Access Query direct in MS Access : I wrote Select * from TableA where field1 like '*abc*' Query from Visual Basic : I wrote Select * from TableA where field1 like '%abc%' But query from C#: I don't known how to write! ????? Please help me ! Thanks
1
2746
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint working as alternatively assigned reader obj. to datasource of GridView. Here is the code for the aspx.cs page: ( The reader surely cootains...
1
2790
by: dotnetnovice | last post by:
Hi everybody... I want to show data in the data gridview placed in my form after getting data from my data access layer class through a class... Here is my code in the data access layer class. public class DBHandler { public List<Programs> GetAllPrograms() {
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
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...
0
7397
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5704
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
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...
0
4759
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...
0
3255
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...
0
1612
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
0
473
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.