【问题标题】:Enquiry about reportViewer taking parameters from a form查询reportViewer从表单中取参数
【发布时间】:2012-09-06 01:42:02
【问题描述】:

我对使用ReportViewer 很陌生。我有一个问题,我不知道如何解决。

我有一个日期TextBox 和一个位置TextBox。我的问题是,当用户键入日期和位置时,如何在ReportViewer 中显示相同的数据。下面是一些截图,以便更好地理解。任何帮助将不胜感激。

如果需要更多详细信息,请告诉我。

【问题讨论】:

  • 你的标准是什么?两个字段都需要还是任何一个都可以?恕我直言,有一个“提交”按钮会更好。
  • 最好两个字段都需要。是的,我忘了添加一个按钮。知道如何显示吗?

标签: c# winforms reporting reportviewer


【解决方案1】:

我假设您将在表单中添加一个ShowButton 按钮。但是,您可以使用 TextBox 事件(例如 Focus Lost、Text Changed 等)而不是按钮单击事件。

   private void ShowButton_Click(object sender, EventArgs e)
    {
        DateTime allocationDate = Convert.ToDateTime(allocDateTextBox.Text);
        string   locationName   = locationTextBox.Text;

        //You can create as many datasources matching the name of DataSet in your report
        ReportDataSource rds = new ReportDataSource("DataSet1");
        rds.Value = getData(String.Format("Select * from myTable where theDate={0} AND Location={1}", allocationDate, locationName));

        reportViewer1.LocalReport.DataSources.Clear();

        //add as many datasources created above
        reportViewer1.LocalReport.DataSources.Add(rds);
        reportViewer1.RefreshReport();
    }

   private DataTable getData(string query)
   {
      //Select new record from database based on the new query with the new criteria
      //return the record as DataTable, DataSet or Collection of object
   }

【讨论】:

  • 是否有任何要为 ReportDataSource 添加的引用??
  • 你为什么问?我想这就是你需要的using Microsoft.Reporting.WinForms;
  • 这将用于窗口应用程序。用正确的标签标记您的问题 - winform 或 asp.net
  • 我的错,现在我已经标记了 winform。
  • 对不起,但可以解释一下这一行,“rds.Value = getData(String.Format("Select * from myTable where theDate={0} AND Location={1}", allocationDate,地点名称));”我不清楚这一点。你能给我看一个更简单的例子吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-11
  • 2013-05-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多