A data source instance has not been supplied for the data source 'Request'

妖精的绣舞 提交于 2019-12-04 12:45:34
Iqbal

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.

  1. My data source of RDLC was "dsClientPayList"
  2. I was adding the data source in my code behind like:

    ReportViewer1.LocalReport.DataSources.Clear(); 
    ReportDataSource rd = new ReportDataSource("dsData1", DAL.MyDBModel.snData().Tables[0]);
    ReportViewer1.LocalReport.DataSources.Add(rd);
    

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).

ReportDataSource rd = new ReportDataSource("dsClientPayList", DAL.MyDBModel.snData().Tables[0]);

And it works

Conclusion: The DataSource name must be same in both RDLC and ReportViewer.

Thanks Happy Coding :)

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

ReportDataSource rds = new ReportDataSource("Request", getData());

I would rather do it with "using" statement for correct object disposal and error handling

using (SqlConnection conn = new SqlConnection(connStr)) {
using(SqlCommand comm = new SqlCommand()) {
comm.Connection = conn;
comm.CommandText = sql;

...

try {
conn.Open();
comm.ExecuteNonQuery();
}
catch(SqlException e) {
// in case something is wrong
}
}
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!