gpt4 book ai didi

asp.net-mvc - 报告定义无效。详细信息 : The report definition has an invalid target namespace

转载 作者:行者123 更新时间:2023-12-03 23:17:48 25 4
gpt4 key购买 nike

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.



我正在使用 ASP.NET MVC 框架。当我调用 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 不兼容,原因如下:

  • 升级版本的 Visual Studio 并使用较新的报告模板和较旧的 .dll
  • 从某人使用旧版本的 .dll 开发的存储库中提取代码,并且您正在 Visual Studio 的较新版本中对其进行编辑

  • 解决办法是通过nuget升级.dll的版本。 Visual Studio 2017 需要版本 140.xxx.xx(与 Sql Server 2016 和以前的版本兼容)。寻找 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com