nishant ranjan

nishant ranjan

  • NA
  • 390
  • 0

error in reading datetime value from excel to datatable

Aug 2 2013 5:27 AM
rollno         formno        citycode       firstname       lastname        fathername      gender       dob                   centrecode         examdate
53303          1                   9                     abc            xyz                  pqr                  m            12/13/1995            9003               07/07/2013

the above data is in excel file.


 while (RowIndex <= ShtRange.Rows.Count)
            {
                ColIndex = 0;
                ColFrom = ColFrm;
                if (RowIndex > 1)
                {
                    dtExcel.Rows.Add();

                    while (ColFrom <= ColTo)
                    {
                        if ((ShtRange.Cells[RowIndex, ColFrom] as Excel.Range).Value2 != null)
                            dtExcel.Rows[dtExcel.Rows.Count - 1][ColIndex] = (ShtRange.Cells[RowIndex, ColFrom] as Excel.Range).Value2.ToString();   //error occures here
                     
                        ColIndex++;
                        ColFrom++;
                    }
                }
           

                RowIndex++;


dtexcel is datatable
when starting reading value from excel file, then value till gender are inserted into datatable but when it reads dob then error occurs that   "string was not recognized as valid datetime. couldnot store <35046> in dob column. Expected type is date time.

plz note dob column in dtexcel is of datetime

what is the error in above code? what is couldnot store <35046> in dob column error? from where this value is coming.

Answers (14)