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.
Loading

Iftikar HussainRank #423 · 5.9K reputationPosted Aug 2, 2013, 3:23 AM EDT
Regards,
Iftikar
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 2, 2013, 1:47 AM EDT
Can you put the break point inside the while loop and check what value it is returning dob column from excel?
Regards,
Iftikar
nishant ranjanRank #4,961 · 317 reputationPosted Aug 2, 2013, 1:49 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 2, 2013, 1:52 AM EDT
Regards,
Iftikar
nishant ranjanRank #4,961 · 317 reputationPosted Aug 2, 2013, 1:56 AM EDT
in excel value is correct. here its giving wrong value. i dont know from where this value coming from. this value doesnot exist anywhere in excel
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 2, 2013, 2:07 AM EDT
this
mm/dd/yyyy
and check
Regards,
Iftikar
nishant ranjanRank #4,961 · 317 reputationPosted Aug 2, 2013, 2:12 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 2, 2013, 2:14 AM EDT
Regards,
Iftikar
nishant ranjanRank #4,961 · 317 reputationPosted Aug 2, 2013, 2:20 AM EDT
Excel.Application appExl;
Excel.Workbook workbook;
Excel.Worksheet NwSheet;
Excel.Range ShtRange;
appExl = new Excel.ApplicationClass();
int ColFrom = Convert.ToInt32(ExcelInfo.txtColFrm.Text);
int ColFrm = Convert.ToInt32(ExcelInfo.txtColFrm.Text);
int ColTo = Convert.ToInt32(ExcelInfo.txtColTo.Text);
long RowIndex = 1;
int ColIndex=0;
string strSheetName=ExcelInfo.txtSheetName.Text;
i am able to read all value of this row before dob but when it reads dob then its gives that value i.e., 35046
nishant ranjanRank #4,961 · 317 reputationPosted Aug 2, 2013, 3:19 AM EDT
DateTime conv = DateTime.FromOADate(d);
dtExcel.Rows[dtExcel.Rows.Count - 1][ColIndex] = CONV;
using the above code i am able to get the right value and store in datatable;
but why we have to do so? why its returning value 35046? why we have to parse into double than convert into date time to get it working? kindly let me know?
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 2, 2013, 3:25 AM EDT
Regards,
Iftikar
nishant ranjanRank #4,961 · 317 reputationPosted Aug 2, 2013, 3:28 AM EDT
and yes thanks for the solution.
Iftikar HussainRank #423 · 5.9K reputationPosted Aug 2, 2013, 3:39 AM EDT
http://forums.ni.com/t5/LabVIEW/UNABLE-TO-READ-DATE-FORMAT-DD-MM-YY-FROM-EXCEL/td-p/996302
Regards,
Iftikar
sri har143 reputationPosted Oct 4, 2018, 9:16 PM EDT