我對EF非常陌生,並試圖使用ADO.NET EF在組合框更改事件上填充文本框上的數據。我試着解析所有的東西,但是一直存在錯誤。我的代碼在下面給出.... 請幫助我....在此先感謝。ADO.NET實體框架中的Casting錯誤4
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();
}
}
我試圖ClickBright和喬·伊諾斯建議,但是它不工作尚未... – Jaan 2013-04-10 17:05:40