Data reader help!

S

Shum

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,MessageBoxIcon.Information);


mySqlDataReader.Close();

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

Nicholas Paldino [.NET/C# MVP]

Shum,

Can you attach a compilable piece of code? I can't get VS to make heads
or tails of what you posted.
 
S

sloan

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top