簡體   English   中英

無法在LINQ中將類型'string'隱式轉換為'System.Data.Linq.Binary

[英]Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary in LINQ to SQL

我已經對密碼進行了哈希處理,然后將其插入數據庫,但是這里的問題是每次我嘗試執行此查詢時都會發生

Cannot implicitly convert type 'string' to 'System.Data.Linq.Binary'

在我數據庫accnt_pass的表中是Binary(50),這是我的代碼

//Instantiate a new Hasher Object
var hasher = new Hasher();

hasher.SaltSize = 16;

//Encrypts The password
var encryptedPassword = hasher.Encrypt(txtPass.Text);

Account newUser = new Account();

newUser.accnt_User = txtUser.Text;
newUser.accnt_Position = txtPosition.Text;
newUser.accnt_Pass = encryptedPassword; 

我正在使用Encrypto進行散列,

如果您的sql列是二進制類型,則需要將字符串encryptedPassword轉換為字節數組。 所以代替線

newUser.accnt_Pass = encryptedPassword;

System.Text.UTF8Encoding encoding=new System.Text.UTF8Encoding();
newUser.accnt_Pass = new System.Data.Linq.Binary(encoding.GetBytes(encryptedPassword));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM