尝试执行c#程序时显示错误

时间:2013-10-29 02:39:29

标签: c# rdlc

我正在尝试创建一个rdlc报告但在尝试执行程序时遇到错误

  

错误:“”= DataSource时无法修改Items集合   财产设定。“

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();

}

如果我错过了什么,有人可以评论和帮助吗? 提前致谢

1 个答案:

答案 0 :(得分:2)

您的cboFrom.Items.Add()来电完全错误 使用数据绑定时,您根本无法操纵Items