如何在代码 C# 中为报表查看器提供数据源实例 ASP.NET

How to supply data source instance for report viewer in code C# ASP.NET

我正在尝试从代码加载我的 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 控件中的代码提供数据源实例?

我不得不在 属性 中通过 GUI 在 IDE 中设置数据源。没有它就无法工作,即使我在后面的代码中设置。