2013-04-12 120 views
1

我使用reportviewer與strongly dataset但現在
我需要通過代碼隱藏填充我的reportviewer。但我發現了這個錯誤:
A data source instance has not been supplied for the data source 'ds_blabla'.
這裏是我的代碼餵養數據集:通過代碼隱藏填充reportviewer

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做而不是使用strongly dataset,因爲我需要將parameters傳遞給我的reportviewer。但這些parameters他們可能會有所不同...所以我想通過codebehind

UPDATE
我不喜歡this。現在有沒有消息了,但似乎沒有什麼...

回答

1

在以下行,而不是MyTable,應改爲ds_blabla

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

謝謝。現在錯誤消息不再出現\ o/yeey。但是什麼也沒有出現。我在我的sql管理器上測試了我的查詢,它返回了空集...你能告訴我我的查詢有什麼問題嗎? – Ghaleon

+0

不,因爲我無法訪問您的數據庫。您必須自己解決這個問題;-) –

+0

好了,現在錯誤消失了,但是沒有顯示...數據集不是空的,也許還有其他錯誤? – Ghaleon