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

  • Question

  • User1920384055 posted

    Hi

    I really need help with this problem that I have been working on for some time

    I have an Sql database and a report in asp.net webpage that is showing the contents of the database

    I added a textbox to filter the retrieved contents of the database using a simple SELECT command and then passing the data to a dataset to populate the report with the filtered data. 

    I also added a GridView that I am filling with the same dataset just to see what is happening behind the scenes.

    So when I load the page, it is runing as expected, the report loads all the contents in the database

    When writing the name of a country in the textbox (ex UK) and hitting the button, the Gridview shows the correct selection results (only UK) so the dataset is being filled correctly, but the report generates an error:

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

    I cant understand why this is happening, I have selected the datasource in the reportviewer already

    Any help is appreciated 

    Here is the code of the page Default3.aspx

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
    
    <%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <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>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
        
        </div>
        &nbsp;&nbsp;&nbsp;<asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
    &nbsp;<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
            Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
            WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="978px">
            <LocalReport ReportPath="Report.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
            SelectMethod="GetData" TypeName="DataSet1TableAdapters.NorthwindTableAdapter">
        </asp:ObjectDataSource>
        </form>
    </body>
    </html>
    

    And the Daeault.aspx.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Microsoft.Reporting.WebForms;
    using System.Data;
    using System.Configuration;
    using System.Data.SqlClient;
    
    public partial class Default3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            string CS = ConfigurationManager.ConnectionStrings["DBCS2"].ConnectionString;
            using (SqlConnection con = new SqlConnection(CS))
            {
    
                SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Northwind WHERE([Country]='" + TextBox1.Text + "')", con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                GridView1.DataSource = ds;
                GridView1.DataBind();
    
                ReportDataSource datasource = new ReportDataSource("DataSet1_Northwind", ds.Tables[0]);
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(datasource);        
                ReportViewer1.LocalReport.Refresh();
    
            }    
        }
    }

    Kind regards




    Friday, August 16, 2013 7:14 PM

Answers

  • User2103319870 posted

    Hi,

    Please modify your code like given below

    protected void Button1_Click(object sender, EventArgs e)
            {
                string CS = ConfigurationManager.ConnectionStrings["DBCS2"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
    
                    SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Northwind WHERE([Country]='" + TextBox1.Text + "')", con);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
    
                    ReportDataSource datasource = new ReportDataSource("DataSet1", ds.Tables[0]);
                    ReportViewer1.LocalReport.DataSources.Clear();
                    ReportViewer1.LocalReport.DataSources.Add(datasource);
                    ReportViewer1.LocalReport.Refresh();
    
                }
            }
    

     

    If the above code modification didn’t work.

    Please do ensure that dataset names are same.  In the code you provided the dataset name which you have assigned to report viewer and the dataset name which you use in code behind is different.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 16, 2013 11:41 PM

All replies

  • User2103319870 posted

    Hi,

    Please modify your code like given below

    protected void Button1_Click(object sender, EventArgs e)
            {
                string CS = ConfigurationManager.ConnectionStrings["DBCS2"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
    
                    SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Northwind WHERE([Country]='" + TextBox1.Text + "')", con);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
    
                    ReportDataSource datasource = new ReportDataSource("DataSet1", ds.Tables[0]);
                    ReportViewer1.LocalReport.DataSources.Clear();
                    ReportViewer1.LocalReport.DataSources.Add(datasource);
                    ReportViewer1.LocalReport.Refresh();
    
                }
            }
    

     

    If the above code modification didn’t work.

    Please do ensure that dataset names are same.  In the code you provided the dataset name which you have assigned to report viewer and the dataset name which you use in code behind is different.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 16, 2013 11:41 PM
  • User1920384055 posted

    Hi,
    Please modify your code like given below
    protected void Button1_Click(object sender, EventArgs e)
            {
                string CS = ConfigurationManager.ConnectionStrings["DBCS2"].ConnectionString;
                using (SqlConnection con = new SqlConnection(CS))
                {
    
                    SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Northwind WHERE([Country]='" + TextBox1.Text + "')", con);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
    
                    ReportDataSource datasource = new ReportDataSource("DataSet1", ds.Tables[0]);
                    ReportViewer1.LocalReport.DataSources.Clear();
                    ReportViewer1.LocalReport.DataSources.Add(datasource);
                    ReportViewer1.LocalReport.Refresh();
    
                }
            }

     

    If the above code modification didn’t work.

    Please do ensure that dataset names are same.  In the code you provided the dataset name which you have assigned to report viewer and the dataset name which you use in code behind is different.

    That fixed it

    Thanks a million

    Best wishes

    Saturday, August 17, 2013 5:03 AM