1

我只是想弄清楚如何在 VB.NET 中使用报表查看器。

我几乎到处都在寻找解决此问题的方法,但还没有找到对我有用的方法。我有一个报告查看器,在此之前报告运行结果。但是现在当我在数据库和数据集中添加新列并在报告中添加列时。该列的数据未显示在报告中。

生成报告的代码。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();
4

0 回答 0