locked
Message: A data source instance has not been supplied for the data source 'DataSet1'. RRS feed

  • Question

  • User1259930034 posted

    Hi,

    I'm getting this message when trying to run my Report Viewer

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

    The following code are below:-

    C#

     

    using System;
    using System.Data;
    using System.Data.Odbc;
    using System.Web.UI;
    using Microsoft.Reporting.WebForms;
    
    public partial class rptViewer : System.Web.UI.Page
    {
        private OdbcConnection conn;
        private string _path;
    
        protected void Page_Load(object sender, EventArgs e)
        {
            conn = new OdbcConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
            conn.Open();
    
            if (Request.ApplicationPath == "/")
                _path = "http://" + Request.Url.Host;
            else
                _path = Request.ApplicationPath;
    
            rptGetDataset();
    
            if (!Page.IsPostBack)
            {
                runRptViewer();
            }
        }
    
        private void rptGetDataset()
        {
            DataSet ds = new DataSet();
            ds.DataSetName = "dsNewDataSet";
            string sql = "";
            sql = "SELECT ID, CLIENT_ID, AGENT_ID FROM TBLMAILDELETED";
            OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
            ds.GetXmlSchema();
            da.Fill(ds);
            ds.WriteXmlSchema(_path + "/App_Code/Dataset.xsd");
           }
    
        private DataTable getData()
        {
            DataSet dss = new DataSet();
            string sql = "";
            sql = "SELECT ID, CLIENT_ID, AGENT_ID FROM TBLMAILDELETED";
            OdbcDataAdapter da = new OdbcDataAdapter(sql, conn);
            da.Fill(dss);
            DataTable dt = dss.Tables[0];
            return dt;
        }
    
        private void runRptViewer()
        {
            this.ReportViewer1.Reset();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
            ReportDataSource rds = new ReportDataSource("dsNewDataSet_Table", getData());
            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.DataSources.Add(rds);
            this.ReportViewer1.DataBind();
            this.ReportViewer1.LocalReport.Refresh();
        }
    }

    ASPX

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
                    Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
                    WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="800px">
                    <LocalReport ReportPath="Report.rdlc">
                    </LocalReport>
                </rsweb:ReportViewer>
            </div>
        </form>
    </body>
    </html>

    REPORT.RDLC

    Have a tablix with three columns named ID,CLIENT_ID,AGENT_ID.

    the Dataset properties for the tablix are:-

    Name: dsNewDataSet

    Data source: dsNewDataSet

    Available dataset: Table

     

    Please help me in finding where did I go wrong and help me to rectify it. I tried looking at lots of articles and changing the codes but was unable to resolve this situation

    Thanks in advance.

    Tenny

    Thursday, May 19, 2011 4:19 PM

Answers

  • User-1892736467 posted

    You need to pass on the datasource to the localreport definition explicitly. Something like:

    <LocalReport ReportPath="Report.rdlc">

    <DataSources>
        <rsweb:ReportDataSource DataSourceId="YOUR_DATASOURCE_ID" Name="YOUR_DATASOURCE_NAME" />
    </DataSources>

    </LocalReport>

    This should hopefully solve the issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 19, 2011 10:49 PM