Introduction
In this post (Part 2), I explain how to use Microsoft Report in MVC 4 With Image Fields from a database.In Part 1 I have explained how to use Microsoft Report in MVC 4. But some viewer commented how to do the same with image data from a database.
Prerequisite
I used followings:- .Net framework 4.0
- Entity Framework
- Sql Server 2008
Steps :
Just follow the steps and get result easily.Step - 1 : Create New Project
Go to File > New > Project > Select asp.net mvc4 web application > Entry Application Name > Click OK.Step-2: Add a Database.
Go to Solution Explorer > Right Click on App_Data folder > Add > New item > Select SQL Server Database Under Data > Enter Database name > Add.Step-3: Create table and insert data for show in report
Open Database > Right Click on Table > Add New Table > Add Columns > Save > Enter table name > Ok.Here my database table
Step-4: Add Entity Data Model.
Go to Solution Explorer > Right Click on Project name form Solution Explorer > Add > New item > Select ADO.net Entity Data Model under data > Enter model name > Add.A popup window will come (Entity Data Model Wizard) > Select Generate from database > Next >
Chose your data connection > select your database > next > Select tables > enter Model Namespace > Finish.
Step-5: Add Action for populate data.
Go To Controller > Add your action > write following code and Rebuild your application to get data from Database.Step-6: Add View for show data on page.
Right Click on your Action > Add View > Enter View name > Check Create a strongly-type view > Select your model class > Select Scaffold templete > Select list > Add.View
Run Application.
Look Result show in your browser.
Now Add some links to your view for generate PDF,Excel,Word files containing report data. Add this to your view.
Step-7: Add Reference (Microsoft.ReportViwer.WebForms.dll)
Right Click on references under project folder > Add Reference > Select Microsoft.ReportViwer.WebForms.dll > OK.Step-8: Add Report file(.rdlc) and Design your report.
Add report folder to your projectRight Click on report folder > Add > New item > Select Report under Reporing > Enter report file name > Add.
Here we also have to add Datasource for our report.
Under report data Click on New > Dataset > New > Choose Data Connection > Next > Select Table > Finish.
Now Design your Report looks.
Step-9: Add Action for generate PDF, Excel, Word and Image File for Report Data
Right Click on your Action > Add View > Enter View name > Check Create a strongly-type view > Select your model class > Select Scaffold templete > Select list > Add. Go To Controller > Add your action > write following code and Rebuild your application to get data from Database.