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