Click here to Skip to main content
15,911,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I ma getting this error Cannot perform '<=' operation on System.String and System.Double


C#
string date = System.DateTime.Today.ToString("dd/MM/yyyy"); 
DataTable dtCopyTemplates = drTemplates.CopyToDataTable();
string matching = "LastDate <=" + date ;
DataView dv = new DataView(dtCopyTemplates, matching, "", DataViewRowState.CurrentRows);                       


plz help me.
Posted
Updated 8-Dec-11 17:35pm
v3

Hi,

you should not do string matching with Date and time,

if you would like to do that then you need consider 2 things
1) it should be in yyyyMMdd format
2) it should be of type double not string.

hope you got my point,

thanks
-Amit.
 
Share this answer
 
try using Linq: http://msdn.microsoft.com/en-us/library/bb669073.aspx[^]

refer to the second to the last example.
 
Share this answer
 
 
Share this answer
 
You need to surround your date string in single quotes, as shown below
string matching = "LastDate <= '" + date + "'";
 
Share this answer
 
v2
Comments
Amod Kumar Jaiswal 8-Dec-11 7:41am    
i did this.
it's filler all records from data table.
i want filter only date less then current date.
Hey try this

string matching = "LastDate <='" + date.ToString() +"'"
keep remaining as it is.
 
Share this answer
 
Comments
Amod Kumar Jaiswal 9-Dec-11 7:22am    
i did this.
it's filler all records from data table.
i want filter only date less then current date.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900