当前位置: 动力学知识库 > 问答 > 编程问答 >

how to get records from database based on date range in asp.net linq

问题描述:

I have develop a small web application in that i'm using entity frame work .i want get the records based on the date range and bind that data in gridview how can i write a query using linq..please help me..Here i have post my code what i have try to get records please .....

 var query = from p in entity.Payments

join D in entity.Debit_Method on p.Debit_Method_ID equals D.Debit_Method_ID

join pt in entity.Payment_Type on p.Payment_Type_ID equals pt.Payment_Type_ID

where p.Client_Pmt_Date >='1998-12-01' && p.Client_Pmt_Date<='1999-08-01' && p.Loan_ID=loanid

select new

{

p.Pmt_ID,

p.Loan_ID,

p.Client_Pmt_Date,

p.MtgSvr_Pmt_Start_Date2,

D.Debit_Method_Desc,

p.Total_Debit_Amt,

p.CreditAmt,

p.LenderAmt,

pt.Payment_Type_Desc,

p.Return_Code,

p.Returned_Date

//p.Pmt_ID,

// D.Debit_Method_Desc,

// pt.Payment_Type_Desc,

// p.Client_Pmt_Date,

// p.MtgSvr_Pmt_Start_Date2,

// p.Amt,

// p.CreditAmt,

// p.Loan_ID,

// p.Pmt_Comments

// p.Loan_ID,

};

grdPayments.DataSource = query.ToList();

grdPayments.DataBind();

}

网友答案:

You will need to compare the Date to a DateTime object rather than a string. Here is a LINQ example with POCO (Plain Old CLR Objects):

var dates = new List<DateTime> { new DateTime(2011, 1, 1), new DateTime(2010, 1, 1), new DateTime(2009, 1, 1) };
var result1 = from x in dates where x < new DateTime(2011, 1, 1) && x > new DateTime(2009,1,1) select x;
var result2 = dates.Where(x => x < new DateTime(2011, 1, 1) && x > new DateTime(2009,1,1));
分享给朋友:
您可能感兴趣的文章:
随机阅读: