Conversion from string "" to type 'Double is not valid
I keep getting this error when attempting to execute this code, even after placing a CType around the value and defining it as double?
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 occupant As String = GridView1.Rows(e.RowIndex).Cells(2).Text
Dim room As String = GridView1.Rows(e.RowIndex).Cells(5).Text
Dim building As String = GridView1.Rows(e.RowIndex).Cells(4).Text
Dim find_id = From p In dbDelete.Residents _
Where p.person_name = occupant _
Select p
Dim remove_bed = From p In dbDelete.Beds _
Where p.occupant = find_id.FirstOrDefault.id _
Where p.room = room _
Where p.building = building _
Order By p.id Descending _
Select p
remove_bed.First.occupant = CType(0, Double)
dbDelete.SaveChanges()
' Increase number of open space开发者_如何学运维s in room.
Dim update_occupancy = From p In dbDelete.Rooms _
Where p.room1 = room
Where p.building = building _
Select p
update_occupancy.First.current_occupancy = update_occupancy.First.current_occupancy - 1
dbDelete.SaveChanges()
End Sub
I suspect the problem is in this line:
Where p.occupant = find_id.FirstOrDefault.id _
Are both of these of the same type? The reason I suspect this line is because in another table earlier, you're using occupant
as the name of the person. I would check that the other values in your where clauses also match the types that you are comparing them to as well.
The reason that it may appear that the error is in the assignment line is that the query isn't being performed until you run First
on it. The error is most likely in the query, not in the assignment.
It can't convert empty string to a double. Put in an if statement checking for an empty string and if it is empty then set the double to 0.
精彩评论