【问题标题】:How to supply data source instance for report viewer in code C# ASP.NET如何在代码 C# ASP.NET 中为报表查看器提供数据源实例
【发布时间】: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


【解决方案1】:

我必须在 IDE 中通过 GUI 设置属性中的数据源。没有它也行不通,即使我在后面的代码中设置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多