WinForm下ReportViewer的数据源的问题。

sdctcl 2012-02-03 11:05:29
我在一个按钮下写了如下语句,想输出报表:

private void button1_Click(object sender, EventArgs e)
{
DataTable dt = TuoCheBLL.GetTuoChe(dTPicker1.Value,dTPicker2.Value);

dataGridView1.DataSource = dt;

this.TuoCheReportBindingSource.DataSource = dt;
this.rptViewer.RefreshReport();
}


但是在dataGridView1中能看到输出数据,在对应的TuoCheReport.rdlc中却只能显示表头,不显示数据。

请问是什么原因啊?

(我在MSDN上看到微软的实例输出报表很简单,只有如下语句:

private void Form1_Load(object sender, EventArgs e)
{
// Bind the Product collection to the DataSource.
this.ProductBindingSource.DataSource = m_merchant.GetProducts();
this.reportViewer1.RefreshReport();
}
...全文
221 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdctcl 2012-02-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 fisher2walker 的回复:]

贴我源码给你吧,从我的项目里copy给你的,肯定可以用。

SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet_All ds = new DataSet_All();
da.Fill(ds, "DataTable_Sa");
……
[/Quote]
我看MSDN上的例子,上面很简单,配置完成之后只有几句就能显示报表了:
namespace BusinessObject
{
public partial class Form1 : Form
{
// Instantiate the Merchant class.
private Merchant m_merchant = new Merchant();

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
// Bind the Product collection to the DataSource.
this.ProductBindingSource.DataSource = m_merchant.GetProducts();

this.reportViewer1.RefreshReport();
}
}
}
我也按照上面的来做,只是把数据源换成了我自己定义的:
DataTable dt = TuoCheBLL.GetTuoChe(dTPicker1.Value,dTPicker2.Value);
dataGridView1.DataSource = dt;
this.TuoCheReportBindingSource.DataSource = dt;
怎么就只能显示表头,不能显示内容呢?
sdctcl 2012-02-05
  • 打赏
  • 举报
回复
有人能帮帮我吗?
如露亦如电 2012-02-05
  • 打赏
  • 举报
回复
贴我源码给你吧,从我的项目里copy给你的,肯定可以用。

SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet_All ds = new DataSet_All();
da.Fill(ds, "DataTable_Sa");
DataTable dt = ds.Tables["DataTable_Sa"];
da.Dispose();
conn.Close();

//先清除数据源
reportViewer1.LocalReport.DataSources.Clear();

//设置报表路径
reportViewer1.LocalReport.ReportPath = "c:\\Report_Sa.rdlc";

//准备报表数据源
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet_Sa";
rds.Value = dt;
reportViewer1.LocalReport.DataSources.Add(rds);

//设置报表参数(可选)
ReportParameter rp = new ReportParameter("Parameter_title", WayDataBase.CompName);
this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });

//指定要使用的显示模式的 Microsoft.Reporting.WinForms.DisplayMode 枚举值。有效值为 Normal 或 PrintLayout。
reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);

//加载报表查看器
reportViewer1.RefreshReport();
sdctcl 2012-02-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 manupstairs 的回复:]

C# code

this.TuoCheReportBindingSource.LocalReport.DataSources.Add(dt);
[/Quote]
还是不行啊,提示“System.Windows.Forms.BingdingSource不包含LocalReport的定义”。
我已经添加了using Microsoft.Reporting.WinForms;。
manupstairs 2012-02-03
  • 打赏
  • 举报
回复

this.TuoCheReportBindingSource.LocalReport.DataSources.Add(dt);

4,818

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧