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

__avd commented: Code tag missing. -2

you need this

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

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