我有以下代码:LINQ声明不更新数据库?
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
当我运行它,看着调试都没有问题,但是当我检查数据库表中它应该被插入 - 列值(occupantnum)避风港没有改变 - 他们都是空的!
不确定这是否相关,但请注意,我现在已经更新j显式为整数。我在调试时注意到wResident.occupantnum显示为Type“Integer?” - 但这似乎没有什么区别 - 当我重新运行它时,它仍然表示类型“整数”?
什么是后端服务器? SQL Server?甲骨文? – 2010-07-15 21:26:52
SQL Server 2008在后端。 – davemackey 2010-07-15 21:27:49