C# 无法将数据集分配给C中的ReportDataSource#

C# 无法将数据集分配给C中的ReportDataSource#,c#,winforms,reporting-services,report,C#,Winforms,Reporting Services,Report,我正在尝试将一个数据集作为一个报表的数据源传递,我希望在winform表单上托管的MicrosoftReporting控件的帮助下查看该报表。我正在为此目的使用以下代码,但未能完成任务 private void Form1_Load(object sender, EventArgs e) { // Sql Connection Object SqlConnection con = new SqlConnection(@"Data Source=SE

我正在尝试将一个数据集作为一个报表的数据源传递,我希望在winform表单上托管的MicrosoftReporting控件的帮助下查看该报表。我正在为此目的使用以下代码,但未能完成任务

    private void Form1_Load(object sender, EventArgs e)
    {
        // Sql Connection Object
        SqlConnection con = new SqlConnection(@"Data Source=SEVEN01-PC\SQLEXPRESS;Initial Catalog=RealWorld;Integrated Security=SSPI;");

        // Sql Command Object
        SqlCommand cmd = new SqlCommand("Select * from ProductReorder", con);

        try
        {
            // Open Connection
            con.Open();

            // Dataset Object
            DataSet ds = new DataSet();

            // Sql DataReader Object
            SqlDataReader reader = cmd.ExecuteReader();

            // Fill Data Set
            ds.Tables[0].Load(reader);

            // Close Sql Datareader and Connection Objects
            reader.Close();
            con.Close();

            //provide local report information to viewer
            reportViewer1.LocalReport.ReportEmbeddedResource = "ProductReorder.rptProductReorder.rdlc";

            //prepare report data source
            ReportDataSource rds = new ReportDataSource();
            rds.Name = "dsProductReorder_dtProductReorder";
            rds.Value = ds.Tables[0];
            reportViewer1.LocalReport.DataSources.Add(rds);

            //load report viewer
            this.reportViewer1.RefreshReport();
        }
        catch (Exception ex)
        {

            MessageBox.Show(ex.Message);
        }
    }

任何关于如何将数据集分配给报表数据源的建议

也许你可以试试这个

    LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("dsProductReorder_dtProductReorder", d.Tables[0]));

这对我来说很有用。

我没有收到异常影响(ReportDataSource rds=new ReportDataSource();)这一行无效,因为ReportDataSource()没有VS 2008 intellisense规定的默认/空构造函数,但在大多数示例中,它都是这样初始化的,即使我所遵循的示例也会如上图所示启动。但实际上它会引起语法错误。你确定你使用的名称规范正确吗
ReportTableAdapter ta = new ReportTableAdapter();
var ds= ra.GetData();
ReportDataSource rd = new ReportDataSource("RepotrDS",ds.ToList());