0
我想創建一個RDLC報告,但同時我想執行程序錯誤,而試圖執行C#程序
Error: ""=Items collection cannot be modified when the DataSource property is set."
Private void btnGenerate_Click(object sender, EventArgs e)
{
string connectionstring = "MultipleActiveResultSets=True;Data Source=ECSTSRD;Initial Catalog=SSWSQL;User ID=sswuser;Password=sswuser123";
SqlConnection myconnection = new SqlConnection(connectionstring);
myconnection.Open();
string sql = "SELECT customer, imp_license_no, psq_level FROM customer WHERE customer= @cust1";
SqlCommand custcom = new SqlCommand(sql, myconnection);
custcom.Parameters.AddWithValue("@cust1", cboFrom.SelectedValue.ToString());
SqlDataAdapter da = new SqlDataAdapter(custcom);
DataSet1 ds = new DataSet1();
da.Fill(ds, "whbal");
cboFrom.DataBindings.Clear();
cboTo.DataBindings.Clear();
cboFrom.Items.Add(ds.Tables["whbal"]);
cboFrom.DataSource = ds.Tables["whbal"];
cboFrom.DisplayMember = "customer";
cboFrom.ValueMember = "customer";
myconnection.Close();
reportViewer1.Reset();
reportViewer1.LocalReport.DataSources.Clear();
LocalReport report = new LocalReport();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", customerBindingSource));
report.ReportPath = "Report1.rdlc";
reportViewer1.LocalReport.Refresh();
}
任何人都可以請評論並幫助如果有什麼我錯過了打的錯誤? 在此先感謝
那麼應該如何修改呢? 我發現了很多指導做rdlc報告的網站.. 但是我無法理解爲什麼有些人使用數據集,爲什麼有些人使用數據表.. confusing .. – user2901955
只需刪除該行。你可能也不應該清除數據綁定。 – SLaks
好了,現在錯誤已解決..謝謝這麼多,並讚賞.. BUT ..我可以問另一個問題嗎? 我點擊按鈕後,報表不顯示,組合框項目消失。 你知道錯誤是什麼?我上面的報告編碼是正確的? – user2901955