Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir

i have a data reader rdr and in while function i am using it like

C#
while (rdr.read())
{

fun();

} 

void fun()
{
reader=commond.excecutereader();
while(reader.read())
{
}
reader.close()
}

after the fun function when rdr moves to next record it shows error no data is available. but it has records when i check the query
Posted
Updated 10-Feb-14 19:54pm
v2
Comments
Bernhard Hiller 11-Feb-14 2:55am    
while(reader.read())
{
Show us your code here!
}

1 solution

try this
C#
void fun()
{
try
  {
    reader=commond.excecutereader();
    while(reader.read())
    {
     //do something
    }
  }
catch{//catch error}
finally
  {
  reader.close();
  }
}
 
Share this answer
 
Comments
rajbir singh thind 11-Feb-14 2:48am    
i tried it sir
The14thNoah 11-Feb-14 18:50pm    
and?it still show no record after it reads the first one?
Bernhard Hiller 11-Feb-14 2:57am    
Ever heard of "using"?
It is clear that neither your solution nor "using" would solve the OP's problem, but at least your "solution" would help prevent later errors.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900