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

发布于 2024-11-01 09:30:14 字数 1536 浏览 1 评论 0原文

我正在尝试将数据集作为报告的数据源传递,我想在 winform 表单上托管的 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);
        }
    }

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

I am trying to pass a dataset as a datasource for a report which i want to view with the help of Microsft Reporting Control hosted on a winform's Form. I am using the following code for this purpose but fails in accomplishing the task.

    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);
        }
    }

Any suggestions how to assign the dataset to the report datasource!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甚是思念 2024-11-08 09:30:15

也许你可以尝试这个...

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

Maybe you can try this...

    LocalReport.DataSources.Add(new Microsoft.Reporting.WebForms.ReportDataSource("dsProductReorder_dtProductReorder", d.Tables[0]));
垂暮老矣 2024-11-08 09:30:15
ReportTableAdapter ta = new ReportTableAdapter();
var ds= ra.GetData();
ReportDataSource rd = new ReportDataSource("RepotrDS",ds.ToList());

这对我有用。

ReportTableAdapter ta = new ReportTableAdapter();
var ds= ra.GetData();
ReportDataSource rd = new ReportDataSource("RepotrDS",ds.ToList());

This works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文