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> <asp:GridView ID="GridView1" runat="server"></asp:GridView> <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