I want to show only a single record from an employeeList by ID with crystal report in asp.net MVC. But I don't know how to do it. I can show a whole list. But I can't do it for a single ID. Please help.
I was able to generate .pdf file of one value with ID using CrystalReport, let me show you my code, database and other details.
Note: before you proceed for answer, I believe you have VS2017 and Crystal report in Visual Studio, if you have latest VS 2017, you can download from here
In this project I am using Entity framework and MVC, so here is my code for it :
BlogDbEntities blogDbEntities = new BlogDbEntities();
public ActionResult Index()
{
List<Blog> OneBlog = new List<Blog>();
//Taking only One row using ID
OneBlog = blogDbEntities.Blogs.Where(a => a.BlogId == 1).ToList();
ReportDocument rd = new ReportDocument();
//location of your crystal report in this it is /ProjectFolder/Model/CrystalReport1.rpt
rd.Load(Path.Combine(Server.MapPath("~/Models"), "CrystalReport1.rpt"));
rd.SetDataSource(OneBlog);
Response.Buffer = false;
Response.ClearContent();
Response.ClearHeaders();
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "BlogList.pdf");
}
Here is my database table image:
and here is the Output
If you are new to Crstal report you can generate it using Following steps :
Note: Your table for which you want to show doesn't have any Nullable column, otherwise while generating reports you may get error "Dataset does not support system.nullable"
Please upvote or mark it as answer, if it works, or comment your queries thanks
Its almost the answer, but what I wanted is, suppose I have created an actionlink on the index page "Print", here when I will be clicking it, it will print the details of that particular entry. How can I do that? I have Attached an image. I want to print the amount_received_slip for that particular entry
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly