Invalid attempt to read when no data is present.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • isitha
    New Member
    • Dec 2010
    • 9

    Invalid attempt to read when no data is present.

    Code:
    String SQL1 = @ " select EmpID,ShiftID,EndReading from FinalCalc]"; 
    DBHandlingqqq obj = new DBHandlingqqq();
    SqlDataReader myDataReaderWW = obj.isExist(SQL1);
    String dataemp  = myDataReaderWW.GetString(0);

    Here`s the DBHandlingqqq class....

    Code:
     class DBHandlingqqq
        {
           
    SqlConnection conn = new SqlConnection("Data Source=ISIM-PC\\SQLEXPRESS;Initial Catalog=ISI_SARA;Integrated Security=SSPI"); 
    
    public SqlDataReader isExist(String SQL1)  {
      
    SqlDataReader myDataReader = null;
    conn.Open();
    SqlCommand cmb = conn.CreateCommand();
    cmb.CommandText = SQL1;
    myDataReader = cmb.ExecuteReader();
    return myDataReader;
    }
    }
    the above error occurs when i gonna run it...HELP...!!!
  • Christian Binder
    Recognized Expert New Member
    • Jan 2008
    • 218

    #2
    I think, you've to check if records exist and then read the first record-line.

    Code:
    ...
    SqlDataReader myDataReaderWW = obj.isExist(SQL1);
    if(myDataReaderWW.HasRows && myDataReaderWW.Read())
      String dataemp  = myDataReaderWW.GetString(0);
    Further I think, you should remove the closing sqare bracket in your sql statement (or add an opening bracket before the table name)

    Comment

    • isitha
      New Member
      • Dec 2010
      • 9

      #3
      hey christian,
      it workd pretty nicely....thnx

      regards
      Isitha

      Comment

      Working...