0

Вылетает ошибка:
System.NullReferenceException: "Object reference not set to an instance of an object."

private void    dataUpdate()
    {                 
            dataBase.openConnection();
            for (int index = 0; index < dataGridView.Rows.Count; index++)
            {
                var rowState = (RowState)dataGridView.Rows[index].Cells[4].Value;
            if (rowState == RowState.Existed)
            {
                continue;
                MessageBox.Show(&quot;Найдена!&quot;, &quot;Успешно!&quot;, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }


            if (rowState == RowState.Deleted)
            {
                var id = Convert.ToInt32(dataGridView.Rows[index].Cells[0].Value);
                var deleteQuary = $&quot;delete from teachers_table_2 where id = {id}&quot;;

                var command = new SqlCommand(deleteQuary, dataBase.GetConnection());
                command.ExecuteNonQuery();
            }
        }
        dataBase.closeConnection();                          
}

0 Answers0