WinForm下ReportViewer的数据源的问题。
我在一个按钮下写了如下语句,想输出报表:
C# code
        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上看到微软的实例输出报表很简单,只有如下语句:
C# code
        private void Form1_Load(object sender, EventArgs e)
        {
            // Bind the Product collection to the DataSource.
            this.ProductBindingSource.DataSource = m_merchant.GetProducts();
            this.reportViewer1.RefreshReport();
        }
)
------解决方案--------------------
贴我源码给你吧,从我的项目里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();