我有一个带有一些计算的小型 Windows 应用程序,并填充了我的无类型数据集,即“progDS”。我使用了 MS Access 数据库。如果我使用类型化的数据集,报表会挑选每一行并将其显示在报表查看器上(这不是我的要求)。我一直在尝试做的是只显示必须包含新计算字段的三行。
该应用程序适用于我的部门,接收学生的形式,提供特定程序(数据集“progDS”包含)。RDLC 报告,而 ReportViewer 只接受类型化的数据集,如何覆盖或更改数据集并提供我的,即“progDS”。
我在另一个表单上有 ReportViewer,我能够将数据集“progDS”放入该表单。
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;
using System.Data.OleDb;
namespace FreshFormReport
{
public partial class Form3 : Form
{
Form1 ObjFomr1 = new Form1();
DataSet dsF3 = new DataSet();
DataSet2 dataSet = new DataSet2();
DataTable dtF3 = new DataTable();
BindingSource bs = new BindingSource();
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
try
{
// TODO: This line of code loads data into the 'DataSet2.RpTable' table. You can move, or remove it, as needed.
// this.RpTableTableAdapter.Fill(this.DataSet2.RpTable);
reportViewer1.LocalReport.DataSources.Clear();
// this.reportViewer1.RefreshReport();
Microsoft.Reporting.WinForms.ReportDataSource rptSource = new Microsoft.Reporting.WinForms.ReportDataSource("dsF3", dsF3.Tables["Porgrams"]);
reportViewer1.Reset();
reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
Microsoft.Reporting.WinForms.LocalReport localRep = reportViewer1.LocalReport;
localRep.Refresh();
localRep.ReportEmbeddedResource = "C:\\Users\\******* \\Documents\\Visual Studio 2010\\Projects\\FreshFormReport\\FreshFormReport\\MyReport.rdlc";
rptSource.Name = "MyReport";
//RpTableTableAdapter.Fill(DataSet2.RpTable);
rptSource.Value = DataSet2.RpTable;
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(rptSource);
//string name = localRep.GetDataSourceNames().ToString();
reportViewer1.LocalReport.ReportPath = "C:\\Users\\****** \\Documents\\Visual Studio 2010\\Projects\\FreshFormReport\\FreshFormReport\\MyReport.rdlc";
//reportViewer1.LocalReport.ReportEmbeddedResource = "MyReport.rdlc";
//reportViewer1.Refresh();
reportViewer1.Refresh();
reportViewer1.RefreshReport();
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}
public void F3function(DataSet ds, DataTable dt)
{
try
{
dsF3 = ds;
dtF3 = dt;
bs.DataSource = dt;
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}
}
}