本地报表处理期间发生错误 - C# Windows Form VS2010

发布于 2025-01-05 17:45:24 字数 3609 浏览 1 评论 0 原文

我正在尝试在客户端模式下使用 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;

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

这是我的代码:

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");

    }
}
}

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

请告知!

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:

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

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

Please advise!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

月寒剑心 2025-01-12 17:45:24

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

我遇到同样问题的人(本地报告处理期间发生错误。报告处理期间发生错误。DatasetName)并且我发现了一个问题连接字符串;我必须从使用 Windows 身份验证切换到 sql 身份验证,然后我的报告才起作用。

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

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.

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

我的鱼塘能养鲲 2025-01-12 17:45:24

报表数据源名称与您在 ReportDataSource 类的 Name 属性中提供的名称似乎不匹配。该报告正在等待 EmployeeAttendanceReport。您可能需要尝试将代码中的 Name 属性设置更改为:

dsCustomers.Name = "EmployeeAttendanceReport";

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

dsCustomers.Name = "EmployeeAttendanceReport";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文