代码之家  ›  专栏  ›  技术社区  ›  Ghaleon

通过代码隐藏填充报表查看器

  •  1
  • Ghaleon  · 技术社区  · 13 年前

    我将报表查看器与一起使用 strongly dataset 但现在
    我需要通过codeehind填充我的报告查看器。但我得到了这个错误:
    A data source instance has not been supplied for the data source 'ds_blabla'.
    以下是我提供数据集的代码:

    public DataSet PreencheDS(Relatorios rel)
      {
         DataSet retorno = new DataSet();
         try
           {
             string sql = @"SELECT proj.descricao AS projeto, func.descricao AS funcionalidade, clb.clube AS cliente, ch.descricao
             FROM MyTable ch 
             INNER JOIN table1 proj ON MyTable.projeto = table1.id 
             INNER JOIN table2 func ON MyTable.funcionalidade = table2.id 
             INNER JOIN table3 clb ON MyTable.clube = table3 .id
             WHERE (MyTable.responsavel = @responsavel) AND (MyTable.clube = @clube) AND (MyTable.dt_cadastro >= @dt_inicial) AND (MyTable.dt_cadastro <= @dt_final)";                
                    MySqlCommand cmd = new MySqlCommand();
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add(new MySqlParameter("@responsavel", MySqlDbType.VarChar)).Value = rel.Responsavel_ID;
                    cmd.Parameters.Add(new MySqlParameter("@clube", MySqlDbType.VarChar)).Value = rel.Clube_ID;
                    cmd.Parameters.Add(new MySqlParameter("@dt_inicial", MySqlDbType.DateTime)).Value = rel.Dt_Inicial;
                    cmd.Parameters.Add(new MySqlParameter("@dt_final", MySqlDbType.DateTime)).Value = rel.Dt_Final;
                    retorno = _dal.Consultar(cmd);
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                return retorno;
            }  
    

    这是包含我的 ReportViewer

    protected void Page_Load(object sender, EventArgs e)
        {           
            if (!IsPostBack)
               {
                  rel.Responsavel_ID = Convert.ToInt32(Session["usrValue"].ToString());
                  rel.Clube_ID = Convert.ToInt32(Session["clube_id"].ToString());
                  rel.Dt_Inicial = Session["dt_inicial"].ToString() + " 00:00:00";
                  rel.Dt_Final = Session["dt_final"].ToString() + " 23:59:59";
    
                  DataSet ds = _rel.PreencheDS(rel);
                  ReportDataSource source = new ReportDataSource("MyTable", ds.Tables[0]);              
                  this.ReportViewer1.ProcessingMode = ProcessingMode.Local;
                  this.ReportViewer1.LocalReport.DataSources.Clear();
                  this.ReportViewer1.LocalReport.DataSources.Add(source);
                  this.ReportViewer1.LocalReport.Refresh();
                }
            }  
    

    我想通过 codebehind 而不是使用 强数据集 因为我需要通过 parameters 我的报告查看器。但是这些 参数 它们可能会有所不同。。。所以我想通过 码尾 .

    更新
    我确实喜欢 this 。现在已经没有消息了,但什么也没有出现。。。

    1 回复  |  直到 9 年前
        1
  •  1
  •   Thorsten Dittmar    13 年前

    在以下行中,而不是 MyTable ,应为 ds_blabla :

    ReportDataSource source = new ReportDataSource("MyTable", ds.Tables[0]);