我正试图在列表框的单击事件上填充数据列表框到文本框,但我发现这个错误无法投射'<> f__AnonymousType0`2 [System.String,System.Int32]'类型的对象来键入'System.IConvertible'
其他信息:无法转换类型的对象 '<> f__AnonymousType0`2 [System.String,System.Int32]' 为类型 'System.IConvertible'
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
StudenRecordDataContext std = new StudentRecordDataContext();
int selectedValue = Convert.ToInt32(listBox1.SelectedValue);
StudentRecord sr = std.StudentRecords.Single(s =>s.ID==selectedValue);
txtId.Text = sr.ID.ToString();
txtName.Text = sr.Name;
txtPassword.Text = sr.Password;
txtCnic.Text = sr.CNIC;
txtEmail.Text = sr.Email;
}
我认为错误是在线StudentRecord sr = std.StudentRecords.Single(s =>s.ID==selectedValue);
该错误来自哪里,我需要改变以解决该错误?
没有工作兄弟和ID的类型int –
那么你在哪里得到这个错误? –
从第三行当我使用lambda exp –