作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
The report definition is not valid. Details: The report definition has an invalid target namespace 'http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition' which cannot be upgraded.
setparameter()
将数据设置到 rdlc 设计报告中时出现错误。
viewer.LocalReport.DataSources.Add(new ReportDataSource("SaleDataSet", modelList));
这行代码执行成功,并且报告已经打印。
viewer.LocalReport.SetParameters(parms);
错误来了。
public ActionResult PrintSaleReport(string saleId)
{
try
{
Decimal sId = 0;
if (!string.IsNullOrEmpty(saleId))
{
sId = Convert.ToDecimal(saleId);
}
var saleList = new SaleRepository().GetById(sId);
List<SalesModel> modelList = new List<SalesModel>();
foreach (var item in saleList.SaleHistories)
{
SalesModel obj = new SalesModel();
obj.StockName = item.Stock.Name;
obj.saleQuantity = item.Quantity + "";
obj.SaleHistoryPrice = Math.Round(Convert.ToDecimal(item.SalePrice), 2) + "";
obj.Expr = Convert.ToDecimal(obj.saleQuantity) * Convert.ToDecimal(obj.SaleHistoryPrice) + "";
modelList.Add(obj);
}
var TotalAmount = Math.Round(Convert.ToDecimal(saleList.TotalBill), 2);
var discount = Math.Round(Convert.ToDecimal(saleList.Discount), 2);
var invoiceNumber = DateTime.Now.ToString("dd-MMM-yyyy hh:mm tt");
var itemCount = saleList.SaleHistories.Count();
ReportParameter[] parms = new ReportParameter[1];
parms[0] = new ReportParameter("[TotalAmount]", TotalAmount + "");
//parms[1] = new ReportParameter("[Discount]", discount+"");
//parms[2] = new ReportParameter("[InvoiceId]", invoiceNumber + "");
//parms[3] = new ReportParameter("itemCount", itemCount + "");
var viewer = new ReportViewer();
string path = Path.Combine(Server.MapPath("~/Reports"), "SaleReport.rdlc");
if (System.IO.File.Exists(path))
{
viewer.LocalReport.ReportPath = path;
}
else
{
return View("Index");
}
viewer.LocalReport.SetBasePermissionsForSandboxAppDomain(new PermissionSet(PermissionState.Unrestricted));
viewer.LocalReport.DataSources.Add(new ReportDataSource("SaleDataSet", modelList));
viewer.LocalReport.SetParameters(parms);
string reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
//string deviceInfo =
// "<DeviceInfo>" +
// "<OutputFormat>" + "PDF" + "</OutputFormat>" +
// "<PageWidth> 8.5in</PageWidth>" +
// "<PageHeight> 11in</PageHeight>" +
// "<MarginTop>0.5in</MarginTop>" +
// "<MarginLeft>1in</MarginLeft>" +
// "<MarginRight>1in</MarginRight>" +
// "<MarginBottom>1in</MarginBottom>" +
// "</DeviceInfo>";
renderedBytes = viewer.LocalReport.Render(
reportType,
null,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings
);
return File(renderedBytes, mimeType);
}
catch (Exception ex)
{
string message = ex.Message;
string innermesasge = ex.InnerException.Message;
var moreinnerMsg = ex.InnerException.InnerException;
throw ex;
}
}
最佳答案
许多人通过告诉人们编辑旧 RDLC 报告的标题来回答这个问题的各种排列。这是一个可怕的想法。通常,出现此问题是因为您使用的 Microsoft.ReportingServices.ReportViewerControl.WebForms
dll 版本与您尝试运行报告的 Sql Server/Sql server lite 不兼容,原因如下:
Microsoft.ReportingServices.ReportViewerControl.WebForms.140.340.80
关于asp.net-mvc - 报告定义无效。详细信息 : The report definition has an invalid target namespace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46543203/
我是一名优秀的程序员,十分优秀!