问题
I have formed a hash key with the help of HashBytes as below with the multiple fields combination on SQL.
hashbytes('MD5', PID+PNumber+CONVERT(VARCHAR(50),cast(datestamp as binary)) +CONVERT(VARCHAR(50), TCount)+OCD+OSeqNbr+TID) AS VARBINARY(80)
All the above fileds datatypes are below
PID - nvarhcar(30)
PNumber - nvarhcar(30)
datestamp - Datetime
TCount - Int
OCD - varhcar(2)
OSeqNbr - varhcar(10)
TID - nvarhcar(100)
But i need C# equivalent function to get the value , so that i can get the value using c# code on the field values and then passes value to sql then compare the value against to the hash key column.
I have tried as below to get the byte[] value which is equivalent to the hash key binary value. But it is not the same value as sql hash key value.
var key = System.Text.Encoding.Unicode.GetBytes(Event.PID + Event.PNumber +
Event.DateStamp + Event.TCount +
Event.OCD + Event.OSeqNbr +
Event.TID);
Can anybody help on this what i am missing?
来源:https://stackoverflow.com/questions/38739141/convert-sql-hash-bytes-binary-value-multiple-datatype-fields-combination-to-c