[英]Conversion from string “” to type 'Double is not valid
即使在值周圍放置CType並將其定義為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 spaces 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
我懷疑問題出在這一行:
Where p.occupant = find_id.FirstOrDefault.id _
這些都是相同類型的嗎? 我懷疑這行的原因是,在較早的另一個表中,您使用的是occupant
名稱。 我將檢查您的where子句中的其他值是否也與您將它們進行比較的類型匹配。
該錯誤可能出現在分配行中的原因是,直到您對其First
運行,該查詢才被執行。 該錯誤最有可能出現在查詢中,而不是分配中。
它不能將空字符串轉換為雙精度型。 放入if語句,檢查是否有空字符串,如果為空,則將double設置為0。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.