【发布时间】:2015-03-17 14:52:43
【问题描述】:
我正在尝试从代码加载我的 ASP.NET 报告查看器,我收到以下错误 A data source instance has not been supplied for the data source
这是我的代码:
Class_Connection.cnn.Close();
Class_Connection.cnn.Open();
var cmd = new SqlCommand("select * from TT", Class_Connection.cnn);
var dt = new DataTable();
dt.Load(cmd.ExecuteReader());
var source = new ReportDataSource(dt.TableName, dt);
RV_Main.LocalReport.DataSources.Clear();
RV_Main.LocalReport.ReportPath = Server.MapPath("~/Reports/AllTTByLastWeek.rdlc");
RV_Main.LocalReport.DataSources.Add(source);
RV_Main.LocalReport.Refresh();
如何通过不在 GUI 控件中的代码提供数据源实例?
【问题讨论】:
-
查看dt中是否有数据,运行时的dt,TableName是什么?
-
@InitK 好调用,好像没有任何数据,不知道为什么,在dt.Load(cmd.ExecuteReader())上没有报错;跨度>
-
嘿@nate .. 你找到数据源为空的原因了吗?问题解决了吗?
-
@Mahe 我用答案更新了问题。
标签: c# asp.net datasource reportviewer rdlc