只有列标题显示在报表查看器上.没有数据显示

本文关键字:显示 数据 报表 标题 | 更新日期: 2023-09-27 18:18:35

这是关于我之前的问题"报告没有显示在报告查看器上"

我正在开发一个c#应用程序,我需要生成一个报告。我是一个使用数据集,其中充满了来自存储过程的数据,该存储过程从c#代码中获取一个参数。我正在report1中创建一个参数。RDLC并使用来自文本框的数据填充它。当我运行应用程序时,我只能看到报表上的列标题,而作为,它不显示报表查看器上的任何数据。

下面的代码

public void GenerateBranchwiseReport()
    {
        conn.Open();
        SqlCommand BranchReportcmd = new SqlCommand("select [am/bsi name] from masterlookup where [asc type]='BRANCH' group by [am/bsi name]", conn);
        SqlDataReader BranchReportread = BranchReportcmd.ExecuteReader();
        while (BranchReportread.Read())
        {
            BranchManagerName.Add(BranchReportread.GetValue(0).ToString());
        }
        conn.Close();
        foreach (string managername in BranchManagerName)
        {
            conn.Open();
            SqlCommand GetReportDatacmd = new SqlCommand();
            GetReportDatacmd.CommandText = "USP_BranchwiseReport";
            GetReportDatacmd.CommandType = CommandType.StoredProcedure;
            GetReportDatacmd.Parameters.Add(new SqlParameter("@BranchManagerName", managername));
            GetReportDatacmd.Connection = conn;
            GetReportDatacmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(GetReportDatacmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            conn.Close();
            reportViewer1.Reset();
            this.reportViewer1.Visible = true;
            string reportname = @"d:'users'administrator'documents'visual studio 2010'Projects'ReportwithParameter'ReportwithParameter'Report1.rdlc";
            this.reportViewer1.LocalReport.ReportPath = @"d:'users'administrator'documents'visual studio 2010'Projects'ReportwithParameter'ReportwithParameter'Report1.rdlc";
            ReportParameter[] param = new ReportParameter[1];
            param[0] = new ReportParameter("ManagerName", managername);
            this.reportViewer1.LocalReport.SetParameters(param);
            ReportDataSource ReportBranch = new ReportDataSource("DatasetWithParameter.USP_BranchwiseReport", ds.Tables[0]);
            this.reportViewer1.LocalReport.ReportEmbeddedResource = reportname;
            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DatasetWithParameter.USP_BranchwiseReport", ds.Tables[0]));
            //this.reportViewer1.LocalReport.DataSources.Add(ReportBranch);
            this.reportViewer1.LocalReport.Refresh();
            //SendEmail();
        } 

只有列标题显示在报表查看器上.没有数据显示

public void GenerateBranchwiseReport()
{
string ManagerNames="";
    conn.Open();
    SqlCommand BranchReportcmd = new SqlCommand("select [am/bsi name] from masterlookup where [asc type]='BRANCH' group by [am/bsi name]", conn);
    SqlDataReader BranchReportread = BranchReportcmd.ExecuteReader();
    while (BranchReportread.Read())
    {
     if (ManagerNames.length==0)
         ManagerNames="'"+BranchReportread.GetValue(0).ToString()+"'";
     else
         ManagerNames =ManagerNames + ",'" + BranchReportread.GetValue(0).ToString()+ "'";
    }
    conn.Close();

  //So now, You have Multiple Managers in ManagerNames string You can send it to SQL, which must used in Where clause with IN (@Managers) in you Stored Procedure.
        conn.Open();
        SqlCommand GetReportDatacmd = new SqlCommand();
        GetReportDatacmd.CommandText = "USP_BranchwiseReport";
        GetReportDatacmd.CommandType = CommandType.StoredProcedure;
        GetReportDatacmd.Parameters.Add(new SqlParameter("@BranchManagerName", ManagerNames));
        GetReportDatacmd.Connection = conn;
        GetReportDatacmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(GetReportDatacmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        conn.Close();
        reportViewer1.Reset();
        this.reportViewer1.Visible = true;
        string reportname = @"d:'users'administrator'documents'visual studio 2010'Projects'ReportwithParameter'ReportwithParameter'Report1.rdlc";
        this.reportViewer1.LocalReport.ReportPath = @"d:'users'administrator'documents'visual studio 2010'Projects'ReportwithParameter'ReportwithParameter'Report1.rdlc";
        ReportParameter[] param = new ReportParameter[1];
        param[0] = new ReportParameter("ManagerName", managername);
        this.reportViewer1.LocalReport.SetParameters(param);
        ReportDataSource ReportBranch = new ReportDataSource("DatasetWithParameter.USP_BranchwiseReport", ds.Tables[0]);
        this.reportViewer1.LocalReport.ReportEmbeddedResource = reportname;
        this.reportViewer1.LocalReport.DataSources.Clear();
        this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DatasetWithParameter.USP_BranchwiseReport", ds.Tables[0]));
        //this.reportViewer1.LocalReport.DataSources.Add(ReportBranch);
        this.reportViewer1.LocalReport.Refresh();
        //SendEmail();