Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So I have been working on this for two days now and search every possible answer for this. What i want to do is to print a report with data from multiple tables. So I have an Orders, Customers, Contracts, ContractProducts, and Products Table. The column that i want to have in my report is the OrderID from Orders, the CustomerID is a foreign key in the Orders and Contracts Table but is a Primary key in the customers table, the ProductID in either the Products table or ContractProducts as the ContractProducts is the bridge table between the contract and products. The last value i want to show is the Quantity which is in the ContractProducts Table. Basically i want to show all the products associated with the orderID. It keeps giving me this error:

System.Runtime.InteropServices.COMException: Error in File OrderReport 18500_7064_{687A694B-A605-4881-A2BB-10ECCD945780}.rpt:
Failed to retrieve data from the database.


but when i dont include the quantity and productid, it lets me export to pdf. Why is that? I've tried joining tem both in linq and query method in mvc but it keeps giving me this error whenever i add the quantity and productid. Please help me.

What I have tried:

I have this code in my controller

var orders = from contractProducts in db.ContractProducts
                             join contracts in db.Contracts on contractProducts.ContractID equals contracts.ContractID
                             join order in db.Orders on contracts.Customer.CustomerID equals order.Customer.CustomerID
                             orderby order.OrderID
                             select new
                             {
                                 OrderID = order.OrderID,
                                 CustomerID = order.CustomerID,
                                 ProductID = contractProducts.ProductID,
                                 Quantity = contractProducts.Quantity
                             };

ReportDocument Rep = new ReportDocument();

                Rep.Load(Path.Combine(Server.MapPath("~/Reports/OrderReport.rpt")));

                Rep.SetDataSource(orders);
                
                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();


                Stream stream = Rep.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stream.Seek(0, SeekOrigin.Begin);
                return File(stream, "application/pdf", "Orders Report.pdf");
Posted
Updated 16-Mar-18 6:19am
Comments
Laxmidhar tatwa technologies 15-Mar-18 23:26pm    
When load the structure to report
Should match to your data source fields

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900