报表查看器上仅显示列标题。没有数据出现

时间:2013-06-14 07:30:18

标签: c# asp.net sql-server rdlc report-viewer2010

这是参考我之前的问题“Report not showing up on report viewer

我正在开发一个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();
        } 

1 个答案:

答案 0 :(得分:0)

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();