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

| 我试图将数据集作为报告的数据源传递,我希望借助winform的Form上托管的Microsft Reporting Control来查看该数据集。我为此使用以下代码,但未能完成任务。
    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]));
    
ReportTableAdapter ta = new ReportTableAdapter();
var ds= ra.GetData();
ReportDataSource rd = new ReportDataSource(\"RepotrDS\",ds.ToList());
这对我有用。     

要回复问题请先登录注册