SubSonic 2.2。我使用存储库记录模式,使用表“约会”,其中约会Id为自动递增int。
我正在尝试更新它,但是当我用完全不同的东西更新字段时,脏列总是为零,我得到一个例外。
System.NullReferenceException:未将对象引用设置为对象的实例。位于A:\ Source \ VS2008 \ Web \ Apps \ janji \ janji \ Classes \ DAL \ AllStructs中SubSonic.SubSonicRepository.Update [T](RepositoryRecord 1 item, String userName) at janji.Janji.Data.DB.Update[T](RepositoryRecord
1项)的SubSonic.DataService.ExecuteQuery(QueryCommand cmd) .vb:janji.WebForm4.SaveData()的第197行:A:\ Source \ VS2008 \ Web \ Apps \ janji \ janji \ UI \ Appt.aspx.vb:第343行
这是我的代码:
Try
If Appointment.AppointmentId > 0 Then
Appointment.AddressName = uxHotel.Text
Appointment.Address = uxAddress.Text
Appointment.AppStartTime = Date.Parse(uxApptDate.SelectedDate.Value.ToShortDateString + " " + uxApptStartTime.SelectedDate.Value.ToShortTimeString)
Appointment.ApptEndTime = Date.Parse(uxApptDate.SelectedDate.Value.ToShortDateString + " " + uxApptEndTime.SelectedDate.Value.ToShortTimeString)
Appointment.Completed = uxCOmpleted.Checked
Appointment.DropNumber = uxDropNum.Text
Appointment.Total = 0
Appointment.EmployeeId = 0
Appointment.Model = uxModel.Text
Appointment.DropAmount = Decimal.Parse(uxDropAmount.SelectedValue)
Appointment.RoomNumber = uxRoom.Text
'If Appointment.DirtyColumns.Count > 0 Then
Janji.Data.DB.Update(Of Janji.Data.Appointment)(Appointment)
'End If
End If
Catch ex As Exception
_ErrorMessage = ex.ToString
RetVal = False
lErrors.Text = _ErrorMessage
lErrors.Visible = True
End Try
答案 0 :(得分:2)
您正在使用我们提供的Structs而不是实例化Appointment对象。做你在这里做的一切,但创建一个约会实例并为其分配值。然后将该实例传递给repo。