我对 EF 非常陌生,并尝试使用 ADO.NET EF 在组合框更改事件的文本框中填充数据。我尝试解析所有内容,但始终存在错误。我的代码在下面给出....请帮助我....在此先感谢。
private List<tSubDepartment> GetSubDepartmentInfo(int deptId)
{
using (DiagnosoftDataContext context = new DiagnosoftDataContext())
{
return (from c in context.tSubDepartments
where c.dpCode == deptId
select c).ToList();
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var subDeptInfo =GetDepartmentInfo((int)comboBox1.SelectedValue); // Error: "Specific cast is not valid"
textBox2.Text = subDeptInfo[0].sdCode.ToString();
textBox3.Text = subDeptInfo[0].sdName;
textBox4.Text = subDeptInfo[0].dpCode.ToString();
}
这是我填充组合框的代码
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.DataSource = GetSubDepartments();
comboBox1.DisplayMember = "sdName";
comboBox1.ValueMember = "sdCode";
}
private List<tSubDepartment> GetSubDepartments()
{
using (DiagnosoftDataContext context = new DiagnosoftDataContext())
{
return (from c in context.tSubDepartments select c).ToList();
}
}