a problem about datereader has empty result when the program step into a if sentense

Trips

Well-known member
Joined
Aug 7, 2010
Messages
2,788
Hello,all
i write some code like this
<div style="color:Black;background-color:White; <pre>
SqlCommand ...= ...
SqlReader reader1=......

<span style="color:Blue; if(.....)
{

SqlCommand ...= ...
SqlReader reader2=......
<span style="color:Blue; if(!reader2.HasRows){
<span style="color:Green; //place A

<span style="color:Blue; while(reader1.reader())
{
.........reader1.GetString(); <span style="color:Green; //place B
}

}


}<span style="color:Blue; else
{








}
reader1.close();
[/code]
i run the programe and it throw exception in the place B, "Invalid attempte to reader when no data is present". but i there is result when i try to run the sql query in studio manager, and i check the reader1, i found that before palce1, the resutl view
has the right result but when continue, the result view become empty.."enumeration yielded no results "

thanks

View the full article
 
Back
Top