谁能帮帮我,初学,遇到这个问题,看不懂报错
if (string.IsNullOrWhiteSpace(txtUser.Text) || string.IsNullOrWhiteSpace(txtPass.Text))
{
MessageBox.Show("请输入用户名和密码!");
txtUser.Focus();
}
else
{
bool bFound = false;
string strFoundUser = txtUser.Text;
string strFoundPass = txtPass.Text;
int nRow = dataGridView1.RowCount;
int targetX = dataGridView1.CurrentCell.RowIndex;
int targetY = dataGridView1.CurrentCell.ColumnIndex;
for (int i = 0; i != nRow; i++)
{
if (strFoundUser == dataGridView1.Rows[i].Cells[1].Value.ToString())
{
dataGridView1.CurrentCell = dataGridView1.Rows[i].Cells[1];
targetX = dataGridView1.CurrentCell.RowIndex;
targetY = dataGridView1.CurrentCell.ColumnIndex;
bFound = true;
break;
}
if (bFound)
{
break;
}
}
if (bFound == false)
{
MessageBox.Show("用户名错误!");
txtUser.Focus();
}
else
{
if (strFoundPass == dataGridView1.Rows[targetX].Cells[targetY+1].Value.ToString())
{
new frmMain();
this.Hide();
}
else
{
MessageBox.Show("密码错误!");
txtUser.Focus();
}
}
}
}
报错截图放在这里
dataGridView1.Rows[i].Cells[1].Value
这个是Null