У меня есть GridView, который показывает результаты и из которого я удаляю результат, используя автоматически созданную ссылку удаления. Мой код позади, чтобы удалить строку и связанную информацию. это:
Private Sub GridView1_RowDeleting(sender As Object, e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
' The deletion of the individual row is automatically handled by the GridView.
Dim dbDelete As New pbu_housingEntities
' Remove individual from the bed.
Dim remove_bed = From p In dbDelete.Beds _
Where p.occupant = GridView1.SelectedRow.Cells(3).Text _
Where p.room = GridView1.SelectedRow.Cells(6).Text _
Where p.building = GridView1.SelectedRow.Cells(5).Text _
Order By p.id Descending _
Select p
remove_bed.First.occupant = ""
dbDelete.SaveChanges()
' Increase number of open spaces in room.
Dim update_occupancy = From p In dbDelete.Rooms _
Where p.room1 = GridView1.SelectedRow.Cells(6).Text
Where p.building = GridView1.SelectedRow.Cells(5).Text _
Select p
update_occupancy.First.current_occupancy = update_occupancy.First.current_occupancy - 1
dbDelete.SaveChanges()
End Sub
Кажется, что он не может захватить удаляемую строку, поэтому он всегда выдает ошибку "Ссылка на объект не установлена на экземпляр объекта".