我正试图在医院预约,当患者选择诊所时,应列出所选诊所的医生姓名
我在Project DataSet向导中的TableAdapter
中进行查询
当我在Dataset
中测试它或者我从ComboBox
向导绑定它时,它工作正常
但是当我尝试使用comboBox.DataSource
更改comboBox的数据时,我得到了
这个错误:
Complex DataBinding接受IList或者数据源作为数据源 IListSource。
这是我的代码:
private void Reservation_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'mRMSDataSet.Departments' table. You can move, or remove it, as needed.
this.departmentsTableAdapter.FillByCLinics(this.mRMSDataSet.Departments);
}
private void clinicNameComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
clinicDoctorsComboBox.DataSource = this.clinicDoctorsTableAdapter.FillByClinicDoctors(this.mRMSDataSet.ClinicDoctors, Convert.ToInt32(clinicNameComboBox.SelectedValue.ToString()));
clinicNameComboBox.DisplayMember = "empName";
clinicNameComboBox.ValueMember = "empId";
}
答案 0 :(得分:1)
错误是自我解释并记录在案。当您为组合框的DataSource
属性分配值时,该值未实现IList
或IListSource
接口,您将收到ArgumentException
:
Complex DataBinding接受IList或者数据源作为数据源 IListSource。
在上面的代码中,您将Fill
方法(通常为int
)的结果分配给DataSource
的{{1}}。相反,您应首先ComboBox
Fill
,然后以这种方式将DataTable
分配给控件的DataTable
:
DataSource