Click here to Skip to main content
15,915,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a table
i want to search the list of orders between abc date to xyz date using entity framework
i used this
my table name is orders, column name is orderDate and datatype is date

// seacch between dates
protected void btn_Searchbydt_Click(object sender, EventArgs e)
{
string frmdate = txtfromdate.Text;
DateTimeOffset offsetfrmDate = DateTimeOffset.Parse(frmdate, null);
string todate = txtfromdate.Text;
DateTimeOffset offsettoDate = DateTimeOffset.Parse(todate, null);

var Query = (from o in db.orders
where EntityFunctions.DiffDays(offsetfrmDate, offsettoDate)
select o).ToArray();
griddetails.DataSource = Query;
griddetails.DataBind();
}


// Search by order id and this worked fine with me
protected void btn_SearchID_Click(object sender, EventArgs e)
{
var Query = (from o in db.orders
where (SqlFunctions.StringConvert((double)o.OrderUserID).Trim()) == txtsearch.Text
select o).ToArray();
griddetails.DataSource = Query;
griddetails.DataBind();
}
Posted
Comments
TryAndSucceed 12-Dec-13 15:11pm    
If you are using LinqKit Namespace, then just use Predicate and add conditions instead of writing the whole query.

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