locked
report rdlc - data source error RRS feed

  • Question

  • User647458646 posted

    I am trying to create a rdlc report but I am currently experiencing the following error --> A data source instance has not been supplied for the data source 'DataSet1'.

    I have assigned my report with datasource from the client-end and as well server end, as shown below:

    Report.aspx.cs

     protected void Page_Load(object sender, EventArgs e)
        {
    
            if (!IsPostBack)
            {
                ReportViewer1.ProcessingMode = ProcessingMode.Local;
                ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/comp2.rdlc");
                dummyDataSet dsCustomers = GetData("select top 20 * from comp2");
                ReportDataSource datasource = new ReportDataSource("Comp2", dsCustomers.Tables[0]);
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(datasource);
            }
    
        }
    
        private dummyDataSet GetData(string query)
        {
            string conString = ConfigurationManager.ConnectionStrings["#######"].ConnectionString;
            SqlCommand cmd = new SqlCommand(query);
            using (SqlConnection con = new SqlConnection(conString))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.Connection = con;
    
                    sda.SelectCommand = cmd;
                    using (dummyDataSet dsCustomers = new dummyDataSet())
                    {
                        sda.Fill(dsCustomers, "DataTable2");
                        return dsCustomers;
                    }
                }
            }
    
        }
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
                <LocalReport ReportPath="comp2.rdlc">
                    <DataSources>
                        <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet2" />
                    </DataSources>
                </LocalReport>
              </rsweb:ReportViewer>
        
              <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="dummyDataSetTableAdapters.comp2TableAdapter"></asp:ObjectDataSource>
        

    Am I missing something in the above codes?  Further hints would be very much appreciated.  Thank you

    Friday, September 12, 2014 10:54 AM

Answers

  • User2103319870 posted

    Please modify your code like given below

            protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!IsPostBack)
                {
                    ReportViewer1.ProcessingMode = ProcessingMode.Local;
                    ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/comp2.rdlc");
                    dummyDataSet dsCustomers = GetData("select top 20 * from comp2");
                    //Change the Dataset name which you assign to ReportDataSource the same as which you have assigned to your ReportDataSource in HTML MarkUp
                    //ReportDataSource datasource = new ReportDataSource("Comp2", dsCustomers.Tables[0]);
                    ReportDataSource datasource = new ReportDataSource("DataSet2", dsCustomers.Tables[0]);
                    ReportViewer1.LocalReport.DataSources.Clear();
                    ReportViewer1.LocalReport.DataSources.Add(datasource);
                }
    
            }

    If the above code modification didn't work.

    Please do ensure that both dataset names are same.  In the code you provided the dataset name as "Comp2" and  the name you have provided in HTML MarkUp is "DataSet2

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 12, 2014 5:32 PM