Reputation: 163
i want to print 1 single record or single registered student details in the crystal report. but here im getting multiple records. how to write code to get single record/ latest record of the table
StudentDBEntities db = new StudentDBEntities();
CrystalReportProduct cr = new CrystalReportProduct();
cr.SetDataSource(db.Students.Select(p => new
{
sno = p.sno,
name =p.sname,
phone=p.phone,
email = p.email,
course = p.course,
date=p.date,
paymentmode=p.paymentMode,
amount=p.amount
}));
this.CrystalReportViewerProduct.ReportSource = cr;
this.CrystalReportViewerProduct.DataBind();
Upvotes: 0
Views: 116
Reputation: 1704
Use OrderByDescending(p => p.sno)
to sort by sno, and then Take(1)
:
cr.SetDataSource(db.Students.Select(p => new
{
sno = p.sno,
name =p.sname,
phone=p.phone,
email = p.email,
course = p.course,
date=p.date,
paymentmode=p.paymentMode,
amount=p.amount
}).OrderByDescending(p => p.sno).Take(1));
Upvotes: 1