我只想弄清楚如何在VB.NET中使用Report Viewer。
我几乎到处寻找解决这个问题的方法,但还没找到一个对我有用的方法。我有一个报表查看器,在此之前报表运行。但现在当我在数据库和数据集中添加新列并在报表中添加列时。该列的数据未显示在报告中。
用于生成报告的代码。 protected void btnRunReport_Click(object sender,EventArgs e) { ReportViewer1.Visible = true;
SqlConnection strConn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalConnectionString"].ConnectionString);
string strSQL = "SELECT b.Description AS Location, ";
strSQL += "ISNULL(SUM(CASE WHEN c.Description = '7.00 AM - 3.00 PM' THEN a.NoofEmployee END),0) AS 'A' , ";
strSQL += "ISNULL(SUM(CASE WHEN c.Description = '3.00 PM - 11.00 PM' THEN a.NoofEmployee END),0) AS 'B', ";
strSQL += "ISNULL(SUM(CASE WHEN c.Description = '11.00 PM - 7.00 AM' THEN a.NoofEmployee END),0) AS 'C', ";
strSQL += "ISNULL(SUM(CASE WHEN c.Description = '7.00 AM - 7.00 PM' THEN a.NoofEmployee END),0) AS 'D', ";
strSQL += "ISNULL(SUM(CASE WHEN c.Description = '7.00 PM - 7.00 AM' THEN a.NoofEmployee END),0) AS 'E', ";
strSQL += "ISNULL(SUM(CASE WHEN c.Description = '8.00 AM - 5.00 PM' THEN a.NoofEmployee END),0) AS 'F', ";
strSQL += "ISNULL(SUM(CASE WHEN c.Description = '7.00 PM - 3.00 AM' THEN a.NoofEmployee END),0) AS 'G', ";
strSQL += "ISNULL(SUM(CASE WHEN c.Description = '11.00 AM - 11.00 PM' THEN a.NoofEmployee END),0) AS 'H' ";
strSQL += "FROM poTransForm a ";
strSQL += "INNER JOIN poLocation b ON a.LocationID = b.ID ";
strSQL += "INNER JOIN poShiftPattern c ON a.ShiftPatternID = c.ID ";
if (cboDept.SelectedIndex == 0)
{
strSQL += "WHERE a.DateRequired = '" + cboSelectDate.SelectedValue + "' AND a.isApproved = 1 ";
}
else
{
strSQL += "WHERE a.DateRequired = '" + cboSelectDate.SelectedValue + "' AND a.DepartmentID = '" + cboDept.SelectedValue + "' AND a.isApproved = 1 ";
}
strSQL += "GROUP BY b.Description ";
SqlDataAdapter da = new SqlDataAdapter(strSQL, strConn);
DataTable dt = new DataTable();
da.Fill(dt);
ObjectDataSource1.TypeName = "HumanResource.DSSummaryTableAdapters.";
List<summary> lst = new List<summary>();
foreach (DataRow r in dt.Rows)
{
summary T = new summary();
T.Location = r["Location"].ToString();
T.A = r["A"].ToString();
T.B = r["B"].ToString();
T.C = r["C"].ToString();
T.D = r["D"].ToString();
T.E = r["E"].ToString();
T.F = r["F"].ToString();
T.G = r["G"].ToString();
T.H = r["H"].ToString();
//T.NoofEmployee = Convert.ToInt32(r["NoofEmployee"]).ToString();
lst.Add(T);
}
ReportParameter rp = new ReportParameter("DateRange", cboSelectDate.SelectedItem.Text);
ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource report = new ReportDataSource("DataSet1", lst);
ReportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });
ReportViewer1.LocalReport.DataSources.Add(report);
ReportViewer1.LocalReport.Refresh();