-1

Hi

I got a error message once ,I read datareader.The error message is"Invalid attempt to read when no data is present".
Previously I go this error,coz I missed the sqldatareader.Read() method.once I put the datareader.Read method
still I got the same error.

         String   str_string1="select ID,renew,reminder,heading from  dbo.StockModifications"; 
         ContractID_Reader2 = db.getdatareader(str_string1);
         ContractID_Reader2.Read();

         if (ContractID_Reader2["ID"] != null)
         {


         }

If there is no records in dbo.StockModifications table then It gives that error message.but is there are data available in
stockmoficaion table there is no error .So I used Contract_Reader.hasrow property also ,but still there is error when there is no data available in datareader

Thanks
Tank50

Edited by mike_2000_17: Fixed formatting

Votes + Comments
Code tag missing.
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by jbisono
0

you need this

if(ContractID_Reader2.HasRows)
{
     while(ContractID_Reader2.Read())
     {
           //Your code here
     }
}
0

HI

yes.I need While loop.I didnt use that coz In my datareader only one record avaliable ,So I thought no need of while loop.Now I fix it.

Thanks
Tank50

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.