2014-03-04 43 views
0

數據源實例尚未提供給數據源'dataset1'。這出現在我的報告查看器中。未知數據源

private void button1_Click(object sender, EventArgs e) 
    { 
     DataSet1 dataSet = new DataSet1(); 

     DataTable table = dataSet.Tables.Add("Language"); 
     table.Columns.Add("A1", Type.GetType("System.String")); 
     table.Columns.Add("A2", Type.GetType("System.String")); 
     table.Columns.Add("A3", Type.GetType("System.String")); 
     DataRow row; 

     row = table.NewRow(); 
     row["A1"] = textBox1.Text; 
     row["A2"] = textBox2.Text; 
     row["A3"] = textBox3.Text; 
     table.Rows.Add(row); 

     //table.Fill(dataSet, "Language"); 
     // MyReport.ProcessingMode = MyReport.Local; 
     MyReport.LocalReport.DataSources.Clear(); 
     MyReport.LocalReport.DataSources.Add(new ReportDataSource("DT", dataSet.Tables[1])); 
     // MyReport.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource()); 
     //MyReport.LocalReport.DataSources.Add(new ReportDataSource("DT", table)); 
     MyReport.LocalReport.Refresh(); 
     MyReport.RefreshReport(); 
} 

回答

1

你的表實際上是指數0,而不是1而如果該報告需要一個名爲數據集「數據集1」,請確保你的名字那樣。

改變這一點。

MyReport.LocalReport.DataSources.Add(new ReportDataSource("DT", dataSet.Tables[1])); 

要這樣:

MyReport.LocalReport.DataSources.Add(new ReportDataSource("dataset1", dataSet.Tables[0])); 

另外,您不必爲了只需添加一個DataTable它和傳由其索引創建DataSet。你可以創建一個單獨的DataTable,這就是它:

DataTable table = new DataTable("Language"); 
... 
... 
MyReport.LocalReport.DataSources.Add(new ReportDataSource("dataset1", table)); 
+0

感謝ü烏拉圭回合的幫助,但之後,我在我的項目寫我們的代碼我面臨的另一個問題。這個錯誤是「本地報表等待處理期間eccurred錯誤」 – Elmohands

+0

感謝ü @Taosique爲你的幫助,但我面臨另一個問題,當我寫你的代碼在我的代碼中的錯誤是「你的本地報告進程中發生的錯誤」終於需要它快速解釋reportViewer不Cristalreport沒有數據庫 使它從一些控件(2文本框,1 datetimpeaker,1Compobox)沒有數據庫我今天需要它,如果你能和我感謝你的青睞 – Elmohands