convert SQL Hash Bytes binary value (Multiple datatype fields combination) to c# equivalent

家住魔仙堡 提交于 2019-12-12 01:42:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!