我正在尝试在客户端模式下使用 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 的属性:
请指教!
最佳答案
我知道已经晚了两年,但我希望这可以帮助其他人
我遇到了同样的问题(本地报告处理期间发生错误。报告处理期间发生错误。DatasetName),我发现连接字符串有问题;我不得不从使用 windows 身份验证切换到 sql 身份验证,然后我的报告起作用了。
显然,按照 Brian Knight 的建议,报表数据源名称必须与您通过 ReportDataSource 对象提供的名称相匹配
关于c# - 本地报表处理时出错 - C# Windows Form VS2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9298330/