本地报表处理过程中发生错误 - C# Windows Form VS2010

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9298330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 06:46:45  来源:igfitidea点击:

An error occurred during local report processing - C# Windows Form VS2010

c#visual-studio-2010sql-server-2008reporting-serviceswindows-forms-designer

提问by Azeem

I am trying to use SQL Server Reporting Services in Client Mode, but something is going fishy. I have two tables in database "IEPL_Attendance_DB": Employee(EmployeeID,EmployeeName) and EmployeeTimeIn(EID,Time_In,Date_Ref,StateFlag) I want to show a report in Windows Form(C# in Visual Studio 2010). The report should be the result of following query:

我正在尝试在客户端模式下使用 SQL Server Reporting Services,但是有些问题。我在数据库“IEPL_Attendance_DB”中有两个表:Employee(EmployeeID,EmployeeName) 和 EmployeeTimeIn(EID,Time_In,Date_Ref,StateFlag) 我想在 Windows 窗体中显示报告(Visual Studio 2010 中的 C#)。报告应该是以下查询的结果:

select e1.EID,e.EmployeeName,convert(varchar(5),SUM(e1.HoursConsumed)/3600)+':'+convert(varchar(5),SUM(e1.HoursConsumed)%3600/60)+':'+convert(varchar(5),(SUM(e1.HoursConsumed)%60)) as workingtime, CONVERT(VARCHAR(10),e1.Date_Ref,111) as Date_Ref
from Employee as e, EmployeeTimeIn as e1
where e.EmployeeID = e1.EID
group by e1.Date_Ref,e1.EID,e.EmployeeName;

I found this article: http://arcanecode.com/2009/03/23/using-sql-server-reporting-services-in-client-mode/, which explains step by step procedure to create report, but when i run the my project, I see following error in report window:
A data source instance has not been supplied for the data source EmployeeAttendanceReport

我找到了这篇文章:http: //arcanecode.com/2009/03/23/using-sql-server-reporting-services-in-client-mode/,它解释了创建报告的分步过程,但是当我运行时在我的项目中,我在报告窗口中看到以下错误:
尚未为数据源 EmployeeAttendanceReport 提供数据源实例

Here is my code:

这是我的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
//Add these to the standard list above
using System.Data.Sql;
using System.Data.SqlClient;
using Microsoft.Reporting.WinForms;

namespace EmployeeManager
{
public partial class Form1 : Form
{

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

        //this.reportViewer1.RefreshReport();

        // Set the processing mode for the ReportViewer to Local
        reportViewer1.ProcessingMode = ProcessingMode.Local;

        LocalReport localReport = reportViewer1.LocalReport;
        localReport.ReportPath = @"F:\Muhammad Anees\Time In\WpfApplication1\EmployeeManager\AttendanceReport.rdlc";

        DataSet dataset = new DataSet("EmployeeAttendanceReport");

        // Get the sales order data
        GetCustomerOrders(ref dataset);

        // Create a report data source for the sales order data
        ReportDataSource dsCustomers = new ReportDataSource();
        dsCustomers.Name = "EmployeeAttendanceReport_EmployeeAttendanceReport";
        dsCustomers.Value = dataset.Tables["Employee"];

        localReport.DataSources.Add(dsCustomers);

        // Refresh the report
        reportViewer1.RefreshReport();
    }

    private void GetCustomerOrders(ref DataSet dsNorthwind)
    {
        string sqlCustomerOrders = "SELECT e1.EID"
          + " ,e.EmployeeName"
          + " ,CONVERT(VARCHAR(10),e1.Date_Ref,111) as Date_Ref"
          + " ,convert(varchar(5),SUM(e1.HoursConsumed)/3600)+':'+convert(varchar(5),SUM(e1.HoursConsumed)%3600/60)+':'+convert(varchar(5),(SUM(e1.HoursConsumed)%60)) as workingtime"
          + "  FROM Employee as e, EmployeeTimeIn as e1"
          + "  WHERE e.EmployeeID=e1.EID"
          + "  GROUP BY e1.Date_Ref,e1.EID,e.EmployeeName";

        SqlConnection connection = new
          SqlConnection("Data Source=AZEEMPC; " +
                        "Initial Catalog=IEPL_Attendance_DB; " +
                        "Trusted_Connection = true;");

        SqlCommand command =
            new SqlCommand(sqlCustomerOrders, connection);

        SqlDataAdapter EmployeeAttendanceReportAdapter = new
            SqlDataAdapter(command);

        EmployeeAttendanceReportAdapter.Fill(dsNorthwind, "EmployeeAttendanceReport");

    }
}
}

Notes:
1. SQL Query is working fine and i can see the output this query in sql server management studio.
2. Here is the properties of DataSet: DataSet Properties

注意:
1. SQL 查询工作正常,我可以在 sql server management studio 中看到此查询的输出。
2.这里是DataSet的属性: 数据集属性

Please advise!

请指教!

回答by Brian Knight

It looks like you have a mismatch between the report data source name and the name you are providing in the Nameproperty of your ReportDataSourceclass. The report is expecting EmployeeAttendanceReport. You may want to try changing the Nameproperty setting in your code to:

看起来您的报告数据源名称与您在类的Name属性中提供的名称不匹配ReportDataSource。该报告期待 EmployeeAttendanceReport。您可能想尝试将Name代码中的属性设置更改为:

dsCustomers.Name = "EmployeeAttendanceReport";

回答by mascab

I know it's two years late but I hope this can help others

我知道已经晚了两年,但我希望这可以帮助其他人

I had the same issue (An error occurred during local report processing. An error occurred during report processing. DatasetName) and I found an issue with the connection string; I had to switch from using windows authentication to sql authentication, then my report worked.

我遇到了同样的问题(本地报告处理期间发生错误。报告处理期间发生错误。DatasetName)我发现连接字符串有问题;我不得不从使用 Windows 身份验证切换到 sql 身份验证,然后我的报告工作。

Obviously the Report Data Source Name must match with the Name you are providing through the ReportDataSource object as Brian Knight suggested

显然,报告数据源名称必须与您通过 ReportDataSource 对象提供的名称匹配,正如 Brian Knight 所建议的