Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...