简体   繁体   English

无法在LINQ中将类型'string'隐式转换为'System.Data.Linq.Binary

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

I've hashed the password and then I'll insert it to the database but the problem here is that each time I try to do this query this occurs 我已经对密码进行了哈希处理,然后将其插入数据库,但是这里的问题是每次我尝试执行此查询时都会发生

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

in my table in the database accnt_pass is Binary(50), here's my code 在我数据库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; 

and I am using Encrypto for hashing, 我正在使用Encrypto进行散列,

You need to convert the string encryptedPassword to a byte array if your sql column is of binary type. 如果您的sql列是二进制类型,则需要将字符串encryptedPassword转换为字节数组。 So instead of the line 所以代替线

newUser.accnt_Pass = encryptedPassword;

put

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.

相关问题 如何将&#39;byte []&#39;类型转换为&#39;System.Data.Linq.Binary&#39; - How to convert type 'byte[]' to 'System.Data.Linq.Binary' LINQ,聚合操作不支持“System.Data.Linq.Binary”类型 - The type 'System.Data.Linq.Binary' is not supported in aggregation operations - LINQ 无法从“ System.DateTime”转换为“ System.Data.Linq.Binary”错误 - Cannot convert from 'System.DateTime' to 'System.Data.Linq.Binary' error 如何将内存流转换为System.Data.Linq.Binary? - How to convert Memory Stream to System.Data.Linq.Binary? 类型“ System.Data.Linq.Binary”在未引用的程序集中定义 - Type 'System.Data.Linq.Binary' is defined in an assembly that is not referenced 无法隐式转换System.Linq.IQueryable类型 <string> 串起来 - Cannot implicitly convert type System.Linq.IQueryable<string> to string 无法隐式转换类型 'System.Linq.IQueryable<string> '到'字符串'</string> - Cannot implicitly convert type 'System.Linq.IQueryable<string>' to 'string' 类型&#39;&lt;&gt; f__AnonymousType1`2 [System.String,System.Data.Linq.Binary]&#39;必须声明一个默认(无参数)构造函数 - The type '<>f__AnonymousType1`2[System.String,System.Data.Linq.Binary]' must declare a default (parameterless) constructor 无法将&#39;System.Data.Linq.Binary&#39;类型的对象强制转换为&#39;System.Byte []&#39; - Unable to cast object of type 'System.Data.Linq.Binary' to type 'System.Byte[]' 将System.Drawing.Image转换为System.Data.Linq.Binary - Converting System.Drawing.Image to System.Data.Linq.Binary
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM