[英]System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation
[英]System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation
我正在使用實體框架和存儲過程以及水晶報告
我想獲取存儲過程並在水晶報告中查看它
但我收到這個錯誤
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
inner exception
NullReferenceException: Object reference not set to an instance of an object.
This exception was originally thrown at this call stack:
CrystalDecisions.CrystalReports.Engine.Table.Fields.get()
這是存儲過程
USE [PayRoll]
GO
/****** Object: StoredProcedure [dbo].[SR1] Script Date: 12/09/2020 15:41:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[SR1]
As
BEGIN
SELECT
EmployeeCode,EmployeeName,JopName,Date_Hiring,Nat_Salary
FROM
Employee_List_Code_Name_Jop_DateHiring
END
這是調用存儲過程錯誤的代碼 rpt.SetDataSource(bs);
if(Report_Number == "2")
{
var Employee_Data = db.Database.SqlQuery<Table>("EXEC SR1").ToList();
bs.DataSource = Employee_Data;
}
//
//
//
ReportDocument rpt = new ReportDocument();
rpt.Load(Application.StartupPath + "\\Report\\Arabic\\" + "R" + Report_Number + ".rpt");
rpt.SetDataSource(bs);
和這個存儲過程類
namespace PayRoll.database
{
using System;
public partial class SR1_Result
{
public int EmployeeCode { get; set; }
public string EmployeeName { get; set; }
public string JopName { get; set; }
public System.DateTime Date_Hiring { get; set; }
public double Nat_Salary { get; set; }
}
}
如何修復此錯誤?
我在 sql 查詢中出錯
代替
查詢
SqlQuery<SR1_Result>
像這樣
if(Report_Number == "2")
{
var Employee_Data = db.Database.SqlQuery<SR1_Result>("SR1").ToList();
bs.DataSource = Employee_Data;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.