【发布时间】:2015-09-16 19:57:14
【问题描述】:
我有一个表单,允许用户输入新数据作为记录。为了保持数据完整性,我将所有预先存在的数据(如果有)复制到记录中,并仅覆盖用户添加了新数据的那些字段。这条新记录被保存到数据库中,旧记录被删除。
我只是想找到最有效的方法来遍历每个字段:
- 确定是否有当前数据需要维护
- 要覆盖的新数据
我需要为字符串、十进制、日期和整数编写相同类型的检查(均可为空)
这是我的字符串检查
Private Function CreateRecordforSubmission() As Business.Casualty
Dim c As Business.Casualty = Casualty
c.alias = CheckStringValues(c.alias, txtAlias.Text.Trim())
Return c
End Function
Private Function CheckStringValues(OldValue As String, newValue As String) As String
If Not OldValue Is Nothing AndAlso Not String.IsNullOrEmpty(newValue) Then
'<-- There is NEW DATA
If Not String.IsNullOrEmpty(newValue) Then
Return newValue
Else
'<-- No NEW DATA, check of there is CURRENT DATA to maintain
If Not OldValue Is Nothing Then
Return OldValue
Else
Return String.Empty
End If
End If
Else
'<-- NO CURRENT DATA AND no changes have been made
Return String.Empty
End If
End Function
【问题讨论】:
-
不幸的是,我将被转移到另一个日期更紧迫的项目,因此我无法对已发布的代码发表评论。 TIA