1
Answer

C#: Reader.GetString(0) Error: Invalid Cast

David Smith

David Smith

14y
4.5k
1
        Can someone assist me, Im getting a error below where there red, Reader.GetString(0);


        private bool GetMDBFile(string fileName, ref Raytheon.Elau.Common.ImportLog impLgStatus)
        {
            FileInfo fn = new FileInfo(fileName);
            impLgStatus = new Raytheon.Elau.Common.ImportLog();

            StringBuilder sbStringBuilder = new StringBuilder();
            OleDbDataReader Reader = null;
            String sCommand = "INVALID COMMAND";
            OleDbCommand objCommand = new OleDbCommand();


            const String query = "SELECT TPC_ID FROM TestObjectEvent;";


            objCommand = new OleDbCommand(sCommand, objConnection);

            try
            {
                objCommand.CommandText = query;
                Reader = objCommand.ExecuteReader();
                while (Reader.Read())
                {
                    tpcIDs.Add(Reader.GetString(0)); -----------------------------------------------------------------Im getting a error at this particular line, saying invalid cast and I dont know why. Its            
                                                                                                                                                           saids invalid cast

   
                }
                Reader.Close();
           
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
 
            }

Answers (1)