0

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();

    }

1 Answer 1

1

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));
Sign up to request clarification or add additional context in comments.

3 Comments

Hi thank you for giving responce..i want get the records using joins so,how can i write query ?can u please help me.
You will need to replace the >='1998-12-01' with >= new DateTime(1998, 12, 1)
i have try to write a code with replace new DateTime(1998, 12, 1) but here and(&&) are not accepted ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.