I'm getting an error on my reportviewer which I am not sure how to correct this.... The error that I am gettings is : " A data source instance has not been supplied for the data source 'Request'." I have tried searching for this, but can't find anything that I can see that is wrong, can somebody please point me in the right direction? This is how my reportvierer looks like:
<rsweb:ReportViewer ID="rptViewer" runat="server" Height="654px"
Width="924px" Font-Names="Verdana" Font-Size="8pt"
InteractiveDeviceInfos="(Collection)" WaitMessageFont-Names="Verdana"
WaitMessageFont-Size="14pt">
<LocalReport ReportPath="Report.rdlc">
</LocalReport>
This is the code I use for the reportviewer:
SqlConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
conn.Open();
if (!Page.IsPostBack)
{
runRptViewer();
}
}
private DataTable getData()
{
DataSet dss = new DataSet();
string sql = "";
sql = "SELECT CC_Request.Company, CC_Request.Attention, CC_Request.Telephone, CC_Request.Email, CC_Items.Model, CC_Items.SerialNo, CC_ItemsRequested.Item, CC_ItemsRequested.Quantity, CC_ItemsRequested.Price, CC_ItemsRequested.ModelID, CC_Items.RequestID FROM CC_Request INNER JOIN CC_Items ON CC_Request.RequestID = CC_Items.RequestID INNER JOIN CC_ItemsRequested ON CC_Items.ModelID = CC_ItemsRequested.ModelID WHERE (CC_Request.Company = 'Alpha') AND (CC_ItemsRequested.ModelID = 20) AND (CC_Items.RequestID = 1)";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(dss);
DataTable dt = dss.Tables[0];
return dt;
}
private void runRptViewer()
{
this.rptViewer.Reset();
this.rptViewer.LocalReport.ReportPath = Server.MapPath("Reports\\Report.rdlc");
ReportDataSource rds = new ReportDataSource("dsNewDataSet_Table", getData());
this.rptViewer.LocalReport.DataSources.Clear();
this.rptViewer.LocalReport.DataSources.Add(rds);
this.rptViewer.DataBind();
this.rptViewer.LocalReport.Refresh();
}
Any help will be greatly appreciated.
EDIT-----------------------
this does not work either:
private DataTable getData()
{
DataTable dtable = new DataTable();
dtable.TableName = "dtNewDataSet_Table";
string sql = "";
sql = "SELECT CC_Request.Company, CC_Request.Attention, CC_Request.Telephone, CC_Request.Email, CC_Items.Model, CC_Items.SerialNo, CC_ItemsRequested.Item, CC_ItemsRequested.Quantity, CC_ItemsRequested.Price, CC_ItemsRequested.ModelID, CC_Items.RequestID FROM CC_Request INNER JOIN CC_Items ON CC_Request.RequestID = CC_Items.RequestID INNER JOIN CC_ItemsRequested ON CC_Items.ModelID = CC_ItemsRequested.ModelID WHERE (CC_Request.Company = 'Alpha') AND (CC_ItemsRequested.ModelID = 20) AND (CC_Items.RequestID = 1)";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
da.Fill(dtable);
DataTable dt = dtable;
return dt;
}
I would rather do it with "using" statement for correct object disposal and error handling
...
You have to set all of the datasources that using in the report.
In this case if there is only one datasource it should be like this
I was also facing this problem that's why I came here.
I figure out the problem and I am posting that here to help some one who get this type of issue.
I was adding the data source in my code behind like:
and it was throwing same error.
Solution:
In my code behind I changed the parameter of ReportDataSource from "dsData1" to "dsClientPayList" (same as in RDLC).
And it works
Conclusion: The DataSource name must be same in both RDLC and ReportViewer.
Thanks Happy Coding :)