2013-04-09 87 views
0

我的朋友即時通訊使用Visual Studio 2008,並且我在c#中開發了一個小型項目,現在我想在其中添加報告(.rdc reports)。這裏是我的代碼c#中的.rdlc報告不顯示任何輸出數據?

try 
     { 
      reportViewer1.Reset(); 
      con.Open(); 
      command.Connection = con; 
      command.CommandType = CommandType.StoredProcedure; 
      command.CommandText = "select_book_specific"; 

      param = new SqlParameter("@isbn", "isbn1"); 
      param.Direction = ParameterDirection.Input; 
      param.DbType = DbType.String; 
      command.Parameters.Add(param); 

      adapter = new SqlDataAdapter(command); 
      adapter.Fill(ds); 


     // for (int i = 0; i <= ds.Tables[0].Columns.Count - 1; i++) 
      // { 

      // MessageBox.Show(ds.Tables[0].Rows[0][i].ToString()); 

      //} For testing purpose 

      this.reportViewer1.LocalReport.ReportPath = @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Report1.rdlc"; 


this.reportViewer1.LocalReport.DataSources.Add(newReportDataSource("Books",ds.Tables[0].TableName.ToString())); 
this.reportViewer1.RefreshReport(); 


} 
catch(exception ex){messageBox.show(ex.message);} 
+2

什麼是你的問題? – 2013-04-09 03:04:20

+0

什麼是'newReportDataSource'你能顯示代碼嗎? – Damith 2013-04-09 03:11:28

+0

@ lc-對不起pal itz一個錯誤我的問題是報告不顯示任何數據? – Roshan 2013-04-09 03:14:01

回答

0

嘗試

try 
{ 
    reportViewer1.Reset(); 
    con.Open(); 
    command.Connection = con; 
    command.CommandType = CommandType.StoredProcedure; 
    command.CommandText = "select_book_specific"; 

    param = new SqlParameter("@isbn", "isbn1"); 
    param.Direction = ParameterDirection.Input; 
    param.DbType = DbType.String; 
    command.Parameters.Add(param); 

    adapter = new SqlDataAdapter(command); 
    adapter.Fill(ds); 
    this.reportViewer1.LocalReport.ReportPath = @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Report1.rdlc"; 
    this.reportViewer1.LocalReport.DataSources.Clear(); 
    this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(ds.DataSetName + "_" + ds.TableName, ds.Tables[0])); 
    this.reportViewer1.LocalReport.Refresh(); 
}catch(Exception ex) 
{ 
    messageBox.show(ex.message); 
} 
+0

當我在我的問題的末尾添加你的答案中,只有的ReportViewer,沒有報告顯示,,, – Roshan 2013-04-09 03:31:29

+0

調試並查看添加之前的表是否具有記錄作爲報告數據源並檢查報告路徑。你有什麼異常嗎?我用完整的代碼更新了我的答案。請檢查。 – Damith 2013-04-09 03:41:58

+0

沒有例外,我使用for循環檢查了數據集,這是正確的報告路徑也是正確的,但reportVierwer中沒有報告顯示 – Roshan 2013-04-09 04:10:04