如何在rdlc报告中的一个数据集中使用多个数据表 [英] How to use multiple datatables in one dataset in rdlc reports
问题描述
你好,
我已经创建了一个rdlc报告并从数据库中重新传输数据如下。
Hello,
I have created an rdlc report and reteriving data from database as below.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ContReportViewer.ProcessingMode = ProcessingMode.Local;
ContReportViewer.LocalReport.ReportPath = Server.MapPath(@"~\PFReports\EmployeePFReport.rdlc");
SelectCon();
SelectEmplDetails();
SelectNomDetails();
SelectBalance();
ContReportViewer.LocalReport.Refresh();
ContReportViewer.ShowPrintButton = true;
ContReportViewer.ShowExportControls = true;
ContReportViewer.ShowRefreshButton = true;
}
}
protected void SelectCon()
{
使用(SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [HRGold]。ConnectionString))
{
使用(SqlCommand cmd = new SqlCommand(query1,con))
{
using(SqlDataAdapter adapt = new SqlDataAdapter(cmd))
{
DataTable dtCont = new DataTable();
adapt.Fill(dtCont);
ReportDataSource dataSource = new ReportDataSource (pfcontributiondataset_ContributionDetails,dtCont);
ContReportViewer.LocalReport.DataSources.Clear();
ContReportViewer.LocalReport.DataSources.Add(dataSource);
}
}
}
}
protected void SelectEmpDetails()
{
using(SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [HRGold使用(SqlCommand cmd = new SqlCommand(query2,con))
{
使用(SqlDataAdapter adapt = new SqlDataAdapter(cmd))
{
DataTable dtEmp = new DataTable();
adapt。填充(dtEmp);
ReportDataSource dataSource = new ReportDataSource(pfcontributiondataset_EmployeeDetails,dtEmp);
ContReportViewer.LocalReport.DataSources.Clear();
ContReportViewer.LocalReport.DataSources.Add(dataSource);
}
}
}
//ContReportViewer.LocalReport.Refresh();
}
protected void SelectNomDetails()
{
using(SqlConnection con = new SqlConnection(System .Configuration.ConfigurationManager.ConnectionStrings [HRGold]。ConnectionString))
{
using(SqlCommand cmd = new SqlCommand(query3,con))
{
使用(SqlDataAdapter adapt = new SqlDataAdapter(cmd))
{
DataTable dtNom = new DataTable();
ReportDataSource dataSource = new ReportDataSource(pfcontributiondataset_EmployeenomineeDetails,dtNom);
ContReportViewer.LocalReport.DataSources.Clear();
ContReportViewer.LocalReport .DataSources.Add(dataSource);
//ContReportViewer.LocalReport.Refresh();
}
}
}
}
protected void SelectBalance()
{
using(SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings [ HRGold] .ConnectionString))
{
使用(SqlCommand cmd = new SqlCommand(query4,con))
{
使用(SqlDataAdapter adapt = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adapt.Fill(dt);
ReportDataSource dataSource = new ReportDataSource(pfcontributiondataset_OpeningBalance,dt);
ContReportViewer.LocalReport.DataSources.Clear();
ContReportViewer.LocalReport.DataSources.Add(d ataSource);
//ContReportViewer.LocalReport.Refresh();
}
}
}
}
但是在报告运行时收到错误
错误1数据区'DataSetName'中缺少数据集名称。
我可以解决这个问题..
protected void SelectCon()
{
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HRGold"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("query1", con))
{
using (SqlDataAdapter adapt = new SqlDataAdapter(cmd))
{
DataTable dtCont = new DataTable();
adapt.Fill(dtCont);
ReportDataSource dataSource = new ReportDataSource("pfcontributiondataset_ContributionDetails", dtCont);
ContReportViewer.LocalReport.DataSources.Clear();
ContReportViewer.LocalReport.DataSources.Add(dataSource);
}
}
}
}
protected void SelectEmpDetails()
{
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HRGold"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("query2", con))
{
using (SqlDataAdapter adapt = new SqlDataAdapter(cmd))
{
DataTable dtEmp = new DataTable();
adapt.Fill(dtEmp);
ReportDataSource dataSource = new ReportDataSource("pfcontributiondataset_EmployeeDetails", dtEmp);
ContReportViewer.LocalReport.DataSources.Clear();
ContReportViewer.LocalReport.DataSources.Add(dataSource);
}
}
}
//ContReportViewer.LocalReport.Refresh();
}
protected void SelectNomDetails()
{
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HRGold"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("query3", con))
{
using (SqlDataAdapter adapt = new SqlDataAdapter(cmd))
{
DataTable dtNom = new DataTable();
ReportDataSource dataSource = new ReportDataSource("pfcontributiondataset_EmployeenomineeDetails", dtNom);
ContReportViewer.LocalReport.DataSources.Clear();
ContReportViewer.LocalReport.DataSources.Add(dataSource);
//ContReportViewer.LocalReport.Refresh();
}
}
}
}
protected void SelectBalance()
{
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HRGold"].ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("query4", con))
{
using (SqlDataAdapter adapt = new SqlDataAdapter(cmd))
{
DataTable dt = new DataTable();
adapt.Fill(dt);
ReportDataSource dataSource = new ReportDataSource("pfcontributiondataset_OpeningBalance", dt);
ContReportViewer.LocalReport.DataSources.Clear();
ContReportViewer.LocalReport.DataSources.Add(dataSource);
//ContReportViewer.LocalReport.Refresh();
}
}
}
}
But while runnig the report the getting the error
Error 1 The data set name is missing in the data region ‘DataSetName’.
Please can i solve this..
推荐答案
这篇关于如何在rdlc报告中的一个数据集中使用多个数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!