2014-02-25 43 views
0

我试图制定一个winform应用程序C#SQL作为备份的数据。报告查看器不显示数据集

我被困在一个特定的地方。

我有一个Winform报表查看器,应该显示要使用两个datetimepicker control检索的数据。这里是我的代码:

`SqlConnection dat = new SqlConnection(@"Data Source=2011-GOA-RCC3\SQLEXPRESS;Initial Catalog=IOB_Comm;Integrated Security=True"); 
      dat.Open(); 
      SqlCommand dat1 = new SqlCommand(); 
      dat1.Connection = dat; 
      dat1.CommandText = "Select * from DCR Where Comp_Date Between '"+ dateTimePicker1.Text +"' And '"+ dateTimePicker2.Text +"' Order By Comp_Date Asc" ; 
      dat1.ExecuteNonQuery(); 
      SqlDataAdapter nb = new SqlDataAdapter(dat1); 
      DataSet mn = new DataSet(); 
      nb.Fill(mn);` 

现在的代码工作正常,直到那里,然后我去数据绑定,排序的,至少可以说,数据集和报表观众之间。这里是代码,..

DataTable dsts = new DataTable(); 
      dsts.TableName = "dt"; 
      dsts = mn.Tables[0]; 
      this.reportViewer1.LocalReport.ReportPath = "Report1.rdlc"; 
      reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local; 
      Microsoft.Reporting.WinForms.ReportDataSource rdc = new Microsoft.Reporting.WinForms.ReportDataSource("dt", dsts); 

      this.reportViewer1.LocalReport.DataSources.Add(rdc); 
      this.reportViewer1.RefreshReport(); 
      dataGridView1.DataSource = mn.Tables[0];//to check if dataset has data. 

这里在谎言我的问题。该代码符合要求,但输出并不如我预期的那样。 我可以查看Datagridview中的数据,但不能查看报告...

你们能帮忙吗?

在此先感谢。

回答

0

我设法解决这个问题我自己...

我只是在RDLC报告添加一组表,并使用默认的数据集(在使用德兴向导创建),以点列重建所有数据表/行数据...

它现在工作非常顺利,我可以查看报告查看器中的所有查询数据...

相关问题