How do I search between two dates that are entered by the user to display. Here is what I have so far.
var qry =
from s in db.Salons
join d in db.Distributors on s.DistributorID equals d.DistributorID
where (
s.CustomerNum.Contains(txtCustomerNum.Text.Trim())
&&
s.DateCreated >= DateTime.Parse((txtDateFrom.Text),DateTime.Parse(txtDateTo.Text))
)
var qry = from s in db.Salons
join d in db.Distributors on s.DistributorID equals d.DistributorID
where (s.CustomerNum.Contains(txtCustomerNum.Text.Trim()) &&
s.DateCreated >= DateTime.Parse((txtDateFrom.Text) &&
s.DateCreated < DateTime.Parse(txtDateTo.Text))
)
var qry = from s in db.Salons
join d in db.Distributors on s.DistributorID equals d.DistributorID
where (s.CustomerNum.Contains(txtCustomerNum.Text.Trim()) &&
s.DateCreated >= DateTime.Parse((txtDateFrom.Text) &&
s.DateCreated =< DateTime.Parse(txtDateTo.Text))
)
The date in sql is displayed as this "4/29/2008 12:00:00 AM" I want to be able the date to be entered as mm/dd/yyyy in the datefrom and dateto textboxes but I still get the error date invalid
kbainey1
Member
68 Points
422 Posts
how to search between dates using linq to sql
Dec 04, 2008 08:57 AM|LINK
How do I search between two dates that are entered by the user to display. Here is what I have so far.
var qry = from s in db.Salons join d in db.Distributors on s.DistributorID equals d.DistributorID where ( s.CustomerNum.Contains(txtCustomerNum.Text.Trim()) && s.DateCreated >= DateTime.Parse((txtDateFrom.Text),DateTime.Parse(txtDateTo.Text)) )LINQ
kipo
All-Star
16475 Points
2811 Posts
Re: how to search between dates using linq to sql
Dec 04, 2008 09:43 AM|LINK
Try with this:
kbainey1
Member
68 Points
422 Posts
Re: how to search between dates using linq to sql
Dec 04, 2008 10:04 AM|LINK
Sorry I get the following error Error 44 Operator '&&' cannot be applied to operands of type 'string' and 'bool'
visualselvam
Member
30 Points
10 Posts
Re: how to search between dates using linq to sql
Dec 04, 2008 12:31 PM|LINK
Hi,
Just try the following code:
var qry = from s in db.Salons
join d in db.Distributors on s.DistributorID equals d.DistributorID
where (s.CustomerNum.Contains(txtCustomerNum.Text.Trim()) &&
s.DateCreated >= DateTime.Parse((txtDateFrom.Text) &&
s.DateCreated =< DateTime.Parse(txtDateTo.Text))
)
kbainey1
Member
68 Points
422 Posts
Re: how to search between dates using linq to sql
Dec 05, 2008 05:08 AM|LINK
kbainey1
Member
68 Points
422 Posts
Re: how to search between dates using linq to sql (Please help )
Dec 05, 2008 06:55 AM|LINK
I still keep on the getting the error && operator can't be applied to type string or bool. Please help.
var qry = from s in db.Salons join d in db.Distributors on s.DistributorID equals d.DistributorID where ( s.CustomerNum.Contains(txtCustomerNum.Text.Trim()) && s.CompanyName.Contains(txtCompanyName.Text.Trim()) && (s.AccountType.Equals(dpAccountType.SelectedValue ?? "") || (dpAccountType.SelectedValue == "")) && (s.AccountStatus.Equals(dpAccountStatus.SelectedValue ?? "") || (dpAccountStatus.SelectedValue == "")) && (s.State.Equals(dpState.SelectedValue ?? "") || (dpState.SelectedValue == "")) && s.ZipCode.Contains(txtZipCode.Text.Trim()) && (s.Country.Equals(dpCountry.SelectedValue ?? "") || (dpCountry.SelectedValue == "")) && s.DateCreated > DateTime.Parse((txtDateFrom.Text) && s.DateCreated < DateTime.Parse(txtDateTo.Text))kbainey1
Member
68 Points
422 Posts
Re: how to search between dates using linq to sql (Please help )
Dec 05, 2008 07:24 AM|LINK
s.DateCreated >=
Convert.ToDateTime(txtDateFrom.Text) && s.DateCreated < Convert.ToDateTime(txtDateTo.Text)Now I get the error."String was not recognized as a valid DateTime"
kipo
All-Star
16475 Points
2811 Posts
Re: how to search between dates using linq to sql (Please help )
Dec 05, 2008 07:27 AM|LINK
You have one parenthesis which shouldn't be there (red one), so change last line in your query from this:
into this:kbainey1
Member
68 Points
422 Posts
Re: how to search between dates using linq to sql (Please help )
Dec 05, 2008 07:50 AM|LINK
The date in sql is displayed as this "4/29/2008 12:00:00 AM" I want to be able the date to be entered as mm/dd/yyyy in the datefrom and dateto textboxes but I still get the error date invalid
String was not recognized as a valid DateTime.
kipo
All-Star
16475 Points
2811 Posts
Re: how to search between dates using linq to sql (Please help )
Dec 05, 2008 08:14 AM|LINK
Insert this line before your query:
and change your last query line into this: