【发布时间】:2019-12-05 10:01:01
【问题描述】:
我正在使用以下 .NET 代码遍历所有输入列以创建列的 HashByte 值,然后确定该行是否已更新。
脚本可以正常工作,直到列具有 NULL 值。如何在不使用 TRY CATCH 块的情况下编写代码?
Imports System.Text
Imports System.Reflection
Imports System.Security.Cryptography
Private sha As SHA256 = New SHA256CryptoServiceProvider() 'used To create the SHA256 hash
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
Try
' create hashbyte column to identify if row has changed
Dim concat As StringBuilder = New StringBuilder("")
' loop over all the input columns of the buffer row
For Each col As PropertyInfo In Row.GetType().GetProperties()
If Not col.Name.ToLower.EndsWith("isnull") AndAlso Not col.Name.ToLower.Equals("hash") Then
MsgBox(col.Name.ToLower)
If col.GetValue(Row, Nothing) Is Nothing Then
concat.Append("")
Else
concat.Append(Convert.ToString(col.GetValue(Row).ToString()))
End If
concat.Append("|")
End If
Next
Dim sHashBytes As String = concat.ToString().Remove(concat.ToString().Length - 1) ' remove the last character of the string
Dim bHashBytes As Byte() = sha.ComputeHash(System.Text.UnicodeEncoding.Unicode.GetBytes(sHashBytes))
Dim sb As StringBuilder = New StringBuilder("")
For i As Integer = 0 To bHashBytes.Length - 1
sb.Append(bHashBytes(i).ToString("X2"))
Next
Row.Hash = "0x" & sb.ToString()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
谢谢,格雷格
【问题讨论】:
标签: sql-server vb.net ssis ssis-2012 isql