how do I used date on searching using Linq. I think I’m missing something on the declaration
string searchName = Request.Form["PersonName"];
DateTime searchDateFrom = Request.Form["ReceivedDateFrom"];
DateTime searchDateTo = Request.Form["ReceivedDateTo"];
var Results = (from va in _db.myTable
where ((va.PersonName.Contains(searchName)
&& (va.ApplicationReceivedDate > searchDateFrom
&& va.ApplicationReceivedDate < searchDateTo)
select va).ToList();
HttpRequest.Form is a NameValueCollection, where you can get strings in it by int/string indexer. That is,
Request.Form["ReceivedDateFrom"]returns a string, you can’t assign it to a variable whose type isDateTimewithout any convert. You can try DateTime.ParseExact method to convert the string to aDateTime. But if you can’t guarantee the string has a correct format, you can use a TryParse method.