c# - 本地报表处理时出错 - C# Windows Form VS2010

标签 c# visual-studio-2010 sql-server-2008 reporting-services windows-forms-designer

我正在尝试在客户端模式下使用 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 的属性: DataSet Properties

请指教!

最佳答案

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

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

显然,按照 Brian Knight 的建议,报表数据源名称必须与您通过 ReportDataSource 对象提供的名称相匹配

关于c# - 本地报表处理时出错 - C# Windows Form VS2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9298330/

相关文章:

C# webclient 和代理服务器

c# - .NET Framework 4 与 .NET Framework 3.5 中的 WCF 有哪些新功能?

visual-studio-2010 - 如何取消 Visual Studio 中正在进行的构建?

c# - 在运行时为报表设置数据源?

Sql 先按顺序,再按下一步

sql-server - 连接到远程 Express Edition 服务器时命名管道错误

c# - 如何使用 C# 在 MVC 布局 View 中编辑 CSS 类

c# - 查找元素返回空字符串..using XPath contains,Text()

c# - 如何将 webbrowser 控件与 Httpwebrequest 一起使用?

sql-server - 数据挖掘 - 预测分析