本文介绍了通过填充codebehind一个的ReportViewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林强数据集,但现在结果
 我需要填充通过codebehind我的ReportViewer。但我发现了这个错误:结果
A数据源实例尚未为数据源'ds_blabla'提供。结果
这里是我的code养活数据集:

Im using reportviewer with strongly dataset but now
I need to populate my reportviewer via codebehind. But I'm getting this error:
A data source instance has not been supplied for the data source 'ds_blabla'.
Here's my code to feed the dataset:

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

And here's the page that contains my 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 来做到这一点,而不是使用大力数据集,因为我需要通过参数我的ReportViewer。但这些参数,他们可能会有所不同。所以我想通过 codebehind 来做到这一点。

I want to do it by codebehind instead of using strongly dataset because I need to pass parameters to my reportviewer. But these parameters they may vary... So I want to do it by codebehind.

更新结果
我不喜欢。现在有没有消息了,但似乎没有什么...

UPDATE
I did like this. Now there's no message anymore, but nothing appears...

推荐答案

在下面的行,而不是 MyTable的,它应该读 ds_blabla

In the following line, instead of MyTable, it should read ds_blabla:

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

这篇关于通过填充codebehind一个的ReportViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 09:33