无法隐式转换类型';字符串';到';Linq to SQL中的System.Data.Linq.Bin

本文关键字:Linq SQL to 中的 System Bin Data 类型 转换 字符串 | 更新日期: 2023-09-27 18:25:38

我已经对密码进行了散列处理,然后将其插入数据库,但这里的问题是每次我尝试进行此查询时,都会出现

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

在我数据库的表中,accnt_pass是二进制(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进行哈希,

无法隐式转换类型';字符串';到';Linq to SQL中的System.Data.Linq.Bin

如果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));