我想使用c#绑定报表查看器。

问题描述:

我在LocalReport.Render方法调用期间一直收到错误 - InnerException =尚未为数据源提供数据源实例。提供的数据集和表有效,因为它与Reportviewer控件一起使用。是否有我遗漏的内容或示例代码错误?



I keep getting an error during the LocalReport.Render method call - InnerException = "A data source instance has not been supplied for the data source". The dataset and table supplied is valid as it works with the Reportviewer control. Is there something I am missing or is the sample code wrong?

<asp:ScriptManager ID="sm" runat="server" />
  
  <rsweb:reportviewer id="rv_ipd"  runat="server" width="900px" font-names="Verdana"

     font-size="8pt" height="617px" interactivedeviceinfos="(Collection)" waitmessagefont-names="Verdana"  waitmessagefont-size="14pt">
    </rsweb:reportviewer>







protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
          //rv_ipd.ProcessingMode = ProcessingMode.Local;
           DataSet1 ds = new DataSet1(); //27-3-2014  DataSet1 is dataset.  DataSet1.xsd
           ReportDataSource datasourse = new ReportDataSource("DataSet1", ds.Tables[0]);
           rv_ipd.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
           rv_ipd.LocalReport.DataSources.Clear();
           rv_ipd.LocalReport.DataSources.Add(datasourse);

       }

   }

删除'rv_ipd .LocalReport.DataSources.Clear();'



得到此错误--->



尚未为数据源'DataSet1_tb_employee'提供数据源实例。
After removing ' rv_ipd.LocalReport.DataSources.Clear();'

Got this error --->

A data source instance has not been supplied for the data source 'DataSet1_tb_employee'.


在报表数据源中提供包含数据集的表名...





provide table name with dataset in report data source...


protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
          //rv_ipd.ProcessingMode = ProcessingMode.Local;
           DataSet1 ds = new DataSet1(); //27-3-2014  DataSet1 is dataset.  DataSet1.xsd
           ReportDataSource datasourse = new ReportDataSource("DataSet1_tableName", ds.Tables[0]);
           rv_ipd.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
           rv_ipd.LocalReport.DataSources.Clear();
           rv_ipd.LocalReport.DataSources.Add(datasourse);

       }

   }


谢谢它现在正在工作





此处的最终密码



Thanks Its Working now


Final Code here

string query = @"SELECT tb_employee.emp_id, tb_employee.emp_name, tb_emp_role.emp_role
                         FROM            tb_emp_role INNER JOIN
                         tb_employee ON tb_emp_role.emp_role_id = tb_employee.emp_role_id";
        ds=dl.fetchrecord(query);
        dl.ConnectionOpen();
        ReportViewer2.Reset();
        ReportDataSource rptsrc = new ReportDataSource("DataSet1_tbl_detail", ds.Tables[0]);
        ReportViewer2.LocalReport.DataSources.Add(rptsrc);
        ReportViewer2.LocalReport.ReportPath = Server.MapPath("report.rdlc");
        ReportViewer2.LocalReport.Refresh();
        ReportViewer2.Visible = true;
        dl.ConnectionClose();