想在同一个页面,用不同的查询条件来调用不同的存储过程,然后把返回的dataset绑定到CrystalReportViewer 的数据源。
现在的问题是CrystalReportViewer_Load事件在search按钮事件前触发,然后提示 ds里没有table 0。怎么办呢,请大家指点一下,急等~
DataSet ds = new DataSet();
ReportDocument optDoc = new ReportDocument(); protected void CrystalReportViewer1_Load(object sender, EventArgs e)
        {
            CrystalReportViewerDataBind(ds.Tables[0]);                            }
   private void CrystalReportViewerDataBind(DataTable dataSource)
        {
            optDoc.SetDataSource(dataSource);
            CrystalReportViewer1.ReportSource = optDoc;
        }

解决方案 »

  1.   

    你应该可以通过ReportDocument的实例去设置数据源吧
    例如:
    private ReportDocument GetReportDocument()
            {
                ReportDocument report = new ReportDocument();
                report.Load(TemplateFullPath);
                report.SetDataSource(Data);
                for (int i = 0; i < report.ParameterFields.Count; i++)
                {
                    report.SetParameterValue(report.ParameterFields[i].Name, "");
                }
                string[] paramNames = ReportModel.GetParameterNames();
                for (int i = 0; i < paramNames.Length; i++)
                {
                    report.SetParameterValue(paramNames[i], ReportModel.GetParameter(paramNames[i]));
                }
                return report;
            }这个方法返回实例,然后在通过
    CrystalReportViewer1.ReportSource = GetReportDocument();
                CrystalReportViewer1.DataBind();
    这样设置。不要直接通过那个事件。