[英]RDLC Reporting using C#
我对Visual Studio C#中的报表完全陌生。我尝试为初学者搜索一些教程,但未成功。.我只是发现了不能真正解释基础知识的代码示例...我编写了一些符合要求并可以运行的代码很好,但是在Visual Studio 2013的报表查看器控件中什么也不显示。我的代码如下:
// This method is in a class named Customers.
// When the user clicks the first column of the datagrid view(I have placed a button
// in the first column of the datagrid) a new form opens (ReportForm) and i pass
// the DataSet called dsReport to its constructor.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0 )
{
DataSet dsReport = new DataSet();
DataTable tbl = dsReport.Tables.Add();
tbl.Columns.Add("CustomerName", typeof(string));
tbl.Columns.Add("CustomerAddress", typeof(string));
tbl.Columns.Add("MaritalStatus", typeof(string));
tbl.Columns.Add("CustomerType", typeof(string));
tbl.Columns.Add("ImagePath", typeof(string));
foreach (Customer cust in customerList)
{
DataRow dr = dsReport.Tables[0].NewRow();
dr["CustomerName"] = cust.Name;
dr["CustomerAddress"] = cust.Address;
dr["MaritalStatus"] = cust.MaritalStatus;
dr["CustomerType"] = cust.CustomerType;
dr["ImagePath"] = cust.ImagePath;
dsReport.Tables[0].Rows.Add(dr);
}
ReportForm report = new ReportForm(dsReport);
report.Show();
}
}
//Following is the code for the ReportForm Class
//I do not get any results in the report viewer
//I just see the message "The source of the report definition has not been specified"
public ReportForm(DataSet dsReport)
{
InitializeComponent();
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(myReportSource);
this.reportViewer1.ProcessingMode = ProcessingMode.Local;
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
}
private void ReportForm_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
/ *请注意,我已经在调试器中运行了代码,并且数据集已正确填充,reportViewer1.LocalReport ..也是如此。我还没有向项目添加任何数据源,也没有添加任何报告文件(.rdl )档案至专案* /
最后,任何人都可以回答以下问题:
Q1。 我是否绝对必须包括一个数据源才能与报表查看器工具一起使用?
Q2。 我是否必须在项目中包括.rdl文件才能显示报告?
Q3。 报表查看器工具和.rdl文件是相同的还是不同的?
ReportViewer是一个知道如何呈现报告的控件。 它仅处理绘图和其他一些后台任务,而不是实际的报告。 实际的报告是.rdl
文件(报告定义语言)。 它包含生成报告的所有说明,但不包含实际数据。 数据源包含报表所依据的数据。
因此,专门回答您的问题:
是的(除非您的报告是完全静态的并且不使用任何数据)。
不,但是您需要以某种方式将.rdl
传递给ReportViewer。 如果您不想将其包含为文件,则可以将其作为资源嵌入到应用程序中,甚至可以将其硬编码为字符串。 ReportViewer具有也接受Stream
的方法,因此可以提供流的任何内容都可以充当.rdl
的源。
正如我在开始时解释的那样,它们是不同的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.