I have the following code:
Dim dbHousing As New dcHousingDataContext
Dim pullresidents = From p In dbHousing.webResidents _
Select p.dorm_building, p.dorm_room, p.occupantnum _
Order By dorm_building, dorm_room
Dim j as integer = 1
Dim previous As String = ""
For Each row In pullresidents
If previous = "" Then
Dim wResident As New webResident
wResident.occupantnum = j
dbHousing.SubmitChanges()
j = j + 1
previous = row.dorm_building & " " & row.dorm_room
Else
If previous = row.dorm_building & " " & row.dorm_room Then
Dim wResident As New webResident
wResident.occupantnum = j
dbHousing.SubmitChanges()
j = j + 1
Else
Dim wResident As New webResident
j = 1
wResident.occupantnum = j
dbHousing.SubmitChanges()
j = j + 1
previous = row.dorm_building & " " & row.dorm_room
End If
End If
Next
When I run it, looking at the debugger everything looks okay but when I check the database table it is supposed to be inserting into – the column values (for occupantnum) haven’t changed – they are all still null!
Not sure if this is related, but note that I’ve now updated j to explicitly be an integer. I noticed while debugging that wResident.occupantnum was appearing as Type “Integer?” – but this doesn’t seem to have made any difference – when I rerun it it still says Type “Integer?”
You iterate over all fetched objects with
For Each row In pullresidentsbut you never modifyrow. So there are no changes that could be send back to the database.