我正在做一个 IS 任务。我有一个以SCB_ActualMIN
数据类型命名的平面文件列string [DT_STR]
。我还有一个脚本组件可以将SCB_ActualMIN
列转换为数字数据类型。我的脚本组件中有此代码
If Not Row.SCBActualDTime_IsNull AndAlso
Not String.IsNullOrEmpty(Row.SCBActualDTime.Trim) Then
Dim dtDate As Date
If DateTime.TryParse(Row.SCBActualDTime.Trim, dtDate) Then
Row.OutPutColumn = dtDate
Else
'If column cannot be parsed
Row.OutPutColumn_IsNull = True
End If
Else
Row.OutPutColumn_IsNull = True
End If
'''''SCBActualDTime
If Not Row.SCBActualMIN_IsNull AndAlso
Not String.IsNullOrEmpty(Row.SCBActualMIN.Trim) Then
Dim MIN As Integer
If Int32.TryParse(Row.SCBActualMIN.Trim, MIN) Then
Row.OutPut2Column = MIN
Else
'If column cannot be parsed
Row.OutPut2Column_IsNull = True
End If
Else
Row.OutPut2Column_IsNull = True
End If
如您所见,转换string
为datetime
数据类型是成功的。虽然对string
to使用相同的代码integer
。将Int32.TryParse(Row.SCBActualMIN.Trim, MIN)
始终返回false连我都值09764377211
在该行代码。还有其他方法可以避免代码重复。
9764377211
大于2147483647
可以分配给的最大值Int32
尝试将值转换为Int64
或Double
代替Int32
Dim MIN As Int64
If Int64.TryParse(Row.SCBActualMIN.Trim, MIN) Then
Row.OutPut2Column = MIN
Else
'If column cannot be parsed
Row.OutPut2Column_IsNull = True
End If
或者
Dim MIN As Double
If Double.TryParse(Row.SCBActualMIN.Trim, MIN) Then
Row.OutPut2Column = MIN
Else
'If column cannot be parsed
Row.OutPut2Column_IsNull = True
End If
您无法避免重复,因为您必须使用它自己的_IsNull
属性来检查每列是否为空。您可以尝试通过创建函数来最小化代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句