Проблемы с DataGridView в C#

Рейтинг: 0Ответов: 0Опубликовано: 24.02.2023

Вылетает ошибка:
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("Найдена!", "Успешно!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                    

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

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

Ответы

Ответов пока нет.