【发布时间】:2018-03-13 19:51:58
【问题描述】:
我正在尝试从我的 Web 应用程序打印订单报告。我必须连接 3 个表才能获得我想要的数据。
例如,我有一个Orders、Contract 和Products 表。我还有另一个表ContractProducts,它是合同和产品的桥梁表。订单表有一个客户 ID 作为外键,合同表也有一个外键作为客户 ID。
我实际上也有一个Customers 表,但我决定只使用订单表中的客户ID,因为我没有使用客户表。长话短说,我需要显示订单 ID、合同 ID 和与订单相关的产品。我有以下代码,它给我一个错误,说检索数据库时出错。但是我使用了 join 方法,它仍然无法正常工作。请帮我。我在这上面花了几个小时:(
//此功能用于出口订单报告
public ActionResult CreateOrderReport()
{
try
{
var orders = (from o in db.Orders
join con in db.Contracts on o.CustomerID equals con.CustomerID
join prod in db.ContractProducts on con.ContractID equals prod.ContractID
select new
{
OrderID = o.OrderID.ToString(),
CustomerID = o.Customer.CustomerID.ToString(),
CustomerName = o.Customer.CustomerName.ToString(),
Phone = o.Customer.Phone.ToString(),
ProductID = prod.ProductID.ToString(),
CategoryID = prod.Product.CategoryID.ToString(),
Brand = prod.Product.Brand.ToString(),
Volume = prod.Product.Volume.ToString(),
PackSize = prod.Product.PackSize.ToString(),
Quantity = prod.Quantity.ToString()
}).ToList();
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");
}
catch (DataException ex)
{
throw;
}
}
【问题讨论】:
-
没有关于数据库错误的更多详细信息?
-
@JeroenHeier 这是它给我的错误...... File OrderReport 5476_25988_{827A9A37-A374-4184-83D7-FB18D2A81587}.rpt 中的错误:无法从数据库中检索数据。说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。异常详细信息:System.Runtime.InteropServices.COMException:文件 OrderReport 5476_25988_{827A9A37-A374-4184-83D7-FB18D2A81587}.rpt 中的错误:无法从数据库中检索数据
标签: c# asp.net-mvc crystal-reports