运行以下代码时,出现异常“System.Nullreferenceexception:object reference not set to an instance of an object”。我相信这与不初始化 allStudents 变量有关,但我不确定 allStudents 是什么类型。
任何帮助表示赞赏
private void showStudents(string c)
{
try
{
using (SMDataClassesDataContext db = new SMDataClassesDataContext())
{
var allStudents = from t in db.tbl_students
where t.current_class == c
select t;
dgViewStudents.ItemsSource = allStudents;
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}