Error Input string was not in a correct format?

I use code as below.

DT_Detail.AsEnumerable().Where(Function(w) Convert.ToInt32(w("APAPDT").ToString.Trim) >= startDatePeriod And 
Convert.ToInt32(w("APAPDT").ToString.Trim) <= endDatePeriod And 
Convert.ToInt32(w("PAID_DATE").ToString.Trim) >= startDatePeriod And 
Convert.ToInt32(w("PAID_DATE").ToString.Trim) <= endDatePeriod).CopyToDataTable()

image

But show error
Filter Date: Input string was not in a correct format.

variable endDatePeriod and startDatePeriod as int.

Please guide mme about it.

Hi, I hope you are well.

Could you perhaps provide more context on what you are trying to achieve?

Try converting the date to string. From there it will be easier to use substring or various available functions to convert to the correct format.

can you paste excel here? @fairymemay

@jack.chan I think it because OutOfMemoryException right?

not sure, i think some of the PAID_DATE / APAPDT fields are the wrong format or blank, can you upload the excel / screenshot it here ?

you can filter out the blank dates by doing this instead

DT_Detail.AsEnumerable().Where(function(z) not z("APAPDT").ToString.Equals("") and not z("PAID_DATE").ToString.Equals("")).CopyToDataTable.Where(Function(w) Convert.ToInt32(w("APAPDT").ToString.Trim) >= startDatePeriod And 
Convert.ToInt32(w("APAPDT").ToString.Trim) <= endDatePeriod And 
Convert.ToInt32(w("PAID_DATE").ToString.Trim) >= startDatePeriod And 
Convert.ToInt32(w("PAID_DATE").ToString.Trim) <= endDatePeriod).CopyToDataTable()

@jack.chan It error as below.

sorry try this

DT_Detail.AsEnumerable().Where(function(z) not z("APAPDT").ToString.Equals("") and not z("PAID_DATE").ToString.Equals("")).CopyToDataTable().AsEnumerable().Where(Function(w) Convert.ToInt32(w("APAPDT").ToString.Trim) >= startDatePeriod And 
Convert.ToInt32(w("APAPDT").ToString.Trim) <= endDatePeriod And 
Convert.ToInt32(w("PAID_DATE").ToString.Trim) >= startDatePeriod And 
Convert.ToInt32(w("PAID_DATE").ToString.Trim) <= endDatePeriod).CopyToDataTable()
2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.