首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >reportviewer rdl文件

reportviewer rdl文件
EN

Stack Overflow用户
提问于 2013-03-13 02:10:33
回答 1查看 2.2K关注 0票数 1

我正在使用ReportViewer控件设计报表,但当我运行该项目时,我收到以下错误:

A data source instance has not been supplied for the data source 'DataSet1'.

下面是我的代码:

代码语言:javascript
复制
            SqlConnection myConnection = new SqlConnection();
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter sqla = new SqlDataAdapter();
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();

            myConnection.ConnectionString = SqlDataSource1.ConnectionString;

            cmd.Connection = myConnection;
            cmd.CommandText ="select * from users";
            cmd.CommandType = CommandType.Text;
            sqla.SelectCommand = cmd;

            sqla.Fill(dt);
            sqla.Fill(ds);

            ReportViewer1.Reset();
            ReportViewer1.LocalReport.DataSources.Clear();
            ReportViewer1.Visible = true;
            ReportViewer1.LocalReport.ReportPath = "reports/allusers.rdl";
            ReportDataSource rds = new ReportDataSource("ds_users",dt);
            ReportViewer1.LocalReport.DataSources.Add(rds);
            ReportViewer1.ZoomMode = ZoomMode.Percent;
            ReportViewer1.LocalReport.Refresh();

我遗漏了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-13 02:33:26

我在创建rdl文件时添加了一个"DataSet1“,因此我需要将数据传递给该Dataset以呈现报表。我将ReportDataSource行更改为以下内容:

代码语言:javascript
复制
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1";
rds.Value = dt;

这样就解决了错误消息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15368878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档