【发布时间】:2020-03-05 10:57:34
【问题描述】:
得到错误:
System.NullReferenceException
在 C# Windows 窗体上的以下代码。
try
{
foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (row.Cells["txtAttendance_Status"].Value.ToString() == "Attended")
{
row.Cells["txtStatus"].Value = true;
}
else if (row.Cells["txtAttendance_Status"].Value.ToString() == "Not Attended")
{
row.Cells["txtStatus"].Value = false;
}
else
{
row.Cells["txtStatus"].Value = false;
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error", ex.ToString());
}
下表:
【问题讨论】:
-
包括您的完整代码,因为不清楚您是来自数据库的
inserting或getting。 -
还包括您的完整错误以了解有关该问题的更多信息。
标签: c# sql .net nullpointerexception