简体   繁体   English

System.Reflection.TargetInvocationException: '调用的目标已抛出异常

[英]System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation

i am using entity framework and storage process and crystal report我正在使用实体框架和存储过程以及水晶报告

i wanna get storage process and view it in crystal report我想获取存储过程并在水晶报告中查看它

but i get this error但我收到这个错误

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()

this is storage process这是存储过程

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 

and this is Code to call storage process error show here rpt.SetDataSource(bs);这是调用存储过程错误的代码 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);

and this storage process class和这个存储过程类

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; }
    }
}

how can fixed this error??如何修复此错误?

i get error in sql query我在 sql 查询中出错

replace代替

SqlQuery查询

SqlQuery<SR1_Result> SqlQuery<SR1_Result>

like this像这样


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.

相关问题 System.Reflection.TargetInvocationException :调用的目标已抛出异常 - System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation System.Reflection.TargetInvocationException:调用的目标已引发异常 - System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation 为什么我收到异常 System.Reflection.TargetInvocationException: &#39;Exception has been throwed by the target of an invocation.&#39;? - Why I'm getting exception System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'? Xamarin Forms System.Reflection.TargetInvocationException: &#39;调用的目标已抛出异常。&#39; - Xamarin Forms System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.' Xamarin.form-Masterdetailpage:System.Reflection.TargetInvocationException:调用的目标已引发异常 - Xamarin.form - Masterdetailpage : System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation Xamarin System.Reflection.TargetInvocationException:调用的目标已引发异常 - Xamarin System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation Xamarin 表单:System.Reflection.TargetInvocationException:调用的目标已抛出异常 - Xamarin Forms: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation 使用 Task.Run 时如何修复“System.Reflection.TargetInvocationException: 'Exception has been throwed by the target of an invocation.'” - How to fix “System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'” when use Task.Run 如何修复“System.Reflection.TargetInvocationException已被抛出” - How to fix “System.Reflection.TargetInvocationException has been thrown” TargetInvocationException:调用的目标引发了异常。 关于数据绑定 - TargetInvocationException: Exception has been thrown by the target of an invocation. on Data Bind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM