I have an excel with column name as Transaction date and various other column as well i have to extract all the rows from this excel whose date is between 15 and 31.
I have used this code HdfcSelcolumns.Select(“Transaction Date LIKE '%/”+Month+“/”+Year+"’ ").CopyToDatatable
Here HdfcSelColumns is a datatable and Transaction Date is a column in my excel and month and year is a string with month and year number.
I am getting an error saying Syntax error: Missing operand after ‘Date’ operator.
(From p in dt.Select()
where convert.ToInt32((Convert.ToDateTime(p.Item(“Transaction Date”))).Day)>15 andconvert.ToInt32((Convert.ToDateTime(p.Item(“Transaction Date”))).Day)<31
select p).ToArray.CopyToDataTable
The above error is removed now however i am getting the below error now after running the query
Assign : String was not recognized as a valid DateTime.
Try This one @aamir (From p in dt.Select() where convert.ToInt32((Convert.ToDateTime(p.Item("Transaction Date"))).Day)>=15 and convert.ToInt32((Convert.ToDateTime(p.Item("Transaction Date"))).Day)<=31 select p).ToArray.CopyToDataTable()
Is your Excel sheet date is in this format, dd/MM/yyyy or dd-MM-yyyy
Else
if the transaction date is not in the above format try this,
(From p in dt.Select()
where convert.ToInt32(DateTime.ParseExact((p.Item(“Transaction Date”)).ToString,stringformat,System.Globalization.CultureInfo.CurrentCulture).Day)>15 and convert.ToInt32(DateTime.ParseExact((p.Item(“Transaction Date”)).ToString,stringformat,System.Globalization.CultureInfo.CurrentCulture).Day)<31
Select p).ToArray.CopyToDataTable()
Sry If it throws any syntax error because i have not tested this code…
Got the below error using the code below
(From p In HdfcSelcolumns.Select()
Where convert.ToInt32(DateTime.ParseExact((p.Item(“Transaction Date”)).ToString, “dd-MM-yyyy”,System.Globalization.CultureInfo.CurrentCulture).Day)>15 And convert.ToInt32(DateTime.ParseExact((p.Item(“Transaction Date”)).ToString, “dd-MM-yyyy”,System.Globalization.CultureInfo.CurrentCulture).Day)<31
Select p).ToArray.CopyToDataTable()
Assign : String was not recognized as a valid DateTime.
That error is throwing because your datacolumn contains other format also…so just try once by creating one seperate excel sheet having a single date format…Even at that time also if it throws exception then you share your excel and xaml.