我正試圖在列表框的單擊事件上填充數據列表框到文本框,但我發現這個錯誤無法投射'<> 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 –