c# winform 程序 开发环境 vs2010 。 要使用报表rdlc,这时候需要绑定数据源,xxx.xsd. 的数据集。 如果绑定数据库的表结构的话 有2个问题, 1.表可能放的是很多外键, 这不是我要显示在报表中的内容。 2. 破坏了三层结构。  所以新建了一个.xsd 数据集,DataSet1, 在DataSet1中 新建了一个表dt。 这个表的字段结构就是我要显示的。然后用rdlc去绑定这个数据集。  这个表现在是没有数据的。 数据我是从Bll层得到存放在另外一个表  dt1里。(这2个表的结构是一样的)。 问题是我该如何让这个dt1 去填充DataSet1里的dt.            或者告诉我有没有别的办法去处理rdlc,比如直接把dt1 绑定到rdlc 绕过DataSet1.  这个我不会。 求教

解决方案 »

  1.   

               reportViewer1.LocalReport.ReportEmbeddedResource = "payment.ReportpaymentDtl.rdlc";//指定reportview 要显示的rdlc报表的名字             ReportParameter rp = new ReportParameter("表头", "表头参数的内容");//带入参数  表头
                // //ReportParameter rp2 = new ReportParameter("上期销售", 上期销售);
                // //ReportParameter rp3 = new ReportParameter("标题", 标题);             this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });
                Microsoft.Reporting.WinForms.ReportDataSource reportDataSource = new ReportDataSource();             reportDataSource.Name = "paymentdtl";       //指定数据源的名字,是你在设计器中指定的
                reportDataSource.Value = dsForGrid.Tables["paymentdtl"];//指定数据源,也就是你查出来的dataTable
                reportViewer1.LocalReport.DataSources.Add(reportDataSource);            //this.reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
                //this.reportViewer1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
                //this.reportViewer1.ZoomPercent = 100;
                //this.reportViewer1.RefreshReport();
                this.reportViewer1.RefreshReport();
            }
      

  2.   

    //绑定报表
                    RepView.LocalReport.ReportPath = "Print\\RDLC\\" + StrFileName + ".rdlc";
                    //绑定数据源
                    //注意dataset1必须和你报表所引用的table 一致
                    //DSView  要打印的数据集  
                    foreach (DataTable dt in DSView.Tables)
                    {
                        ReportDataSource rds = new ReportDataSource(dt.TableName, dt);//注意这里的name和报表中的一致
                        RepView.LocalReport.DataSources.Add(rds);
                    }
    // 参数   HTPam 参数集合
                    if (HTPam != null && HTPam.Count > 0)
                    {
                        ReportParameter[] PS = new ReportParameter[HTPam.Count];
                        int i = 0;
                        foreach (DictionaryEntry de in HTPam)
                        {
                            PS[i] = new ReportParameter(SafeConvert.SafeString(de.Key), SafeConvert.SafeString(de.Value));
                            i++;
                        }
                        RepView.LocalReport.SetParameters(PS);
                    }