【发布时间】:2015-11-05 14:12:29
【问题描述】:
我对 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)文件 到项目 */
最后请大家回答以下问题:
第一季度。我绝对必须包含一个数据源来处理报告吗 查看工具??
第二季度。我是否必须在项目中包含 .rdl 文件才能显示报告?
第三季度。报表查看器工具和 .rdl 文件是否相同? 不一样??
【问题讨论】: